branch develop updated (1292191 -> 5ba6f85)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git from 1292191 Allow application config to execute action on provided class instance (Fixes #2090) new ffc15bb Fix test beacuase printConfig has more than one implementations in ApplicationConfig class new a7df6b1 Support toml format for configuration description new a90f02f Improve mojo design new e6611a0 Use toml format in example new 5ca0fe1 Add missing header files new 0505140 Rename yml files to yaml new c2e4dab clean toml files new ab3e1ca improve doc new 5ba6f85 Use Toml format to describe configuration (Fixes #4056) Merge branch 'feature/4056' into develop The 9 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 5ba6f85230e2836134735f5246235173fbd243fd Merge: ffc15bb ab3e1ca Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 15:50:40 2016 +0200 Use Toml format to describe configuration (Fixes #4056) Merge branch 'feature/4056' into develop commit ab3e1ca783da059be2d87cad6edd55d5d2749bcb Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 15:50:28 2016 +0200 improve doc commit c2e4dab27a6b3fc9aca9996c6e84e5a3e9b986b4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 15:50:19 2016 +0200 clean toml files commit 050514097b86c9946ccb18162afe84360aae03cc Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 15:49:48 2016 +0200 Rename yml files to yaml commit 5ca0fe18e7bbe09525407cea01667998a10327de Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 13:50:12 2016 +0200 Add missing header files commit e6611a047d7178f077c7ce3ffcbde4b4c28efe5b Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 13:44:53 2016 +0200 Use toml format in example commit a90f02f8ace46effe61440f4165c4ce7451ddf7a Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 13:44:51 2016 +0200 Improve mojo design commit a7df6b110d3a22f89a4dc617bc45a4f4963972c1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 13:44:21 2016 +0200 Support toml format for configuration description commit ffc15bbc6d92f57e803bf077a5de437e146506fd Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 11:16:03 2016 +0200 Fix test beacuase printConfig has more than one implementations in ApplicationConfig class Summary of changes: nuiton-config-example/pom.xml | 37 ++++ .../src/main/config/NuitonConfigExample.toml | 37 ++++ .../src/main/config/NuitonConfigExample.yaml | 0 nuiton-config-example/src/site/apt/index.apt.vm | 92 +++------ nuiton-config-maven-plugin/pom.xml | 18 ++ .../nuiton/config/plugin/ConfigMojoSupport.java | 126 +++++++++++++ .../org/nuiton/config/plugin/DescribeMojo.java | 94 +++------- .../org/nuiton/config/plugin/GenerateMojo.java | 119 ++++-------- .../ConfigModelIO.java} | 29 +-- .../config/plugin/io/ConfigModelIOTomlImpl.java | 78 ++++++++ .../ConfigModelIOYamlImpl.java} | 34 ++-- .../config/plugin/io/ReadConfigModelException.java | 22 +-- .../plugin/io/WriteConfigModelException.java | 22 +-- .../src/main/resources/log4j.properties | 1 - nuiton-config-maven-plugin/src/site/apt/index.apt | 4 +- .../plugin/io/ConfigModelIOTomlImplTest.java | 79 ++++++++ .../plugin/io/ConfigModelIOYamlImplTest.java | 79 ++++++++ .../ConfigMoldeIOFixtures.java} | 25 +-- .../src/test/resources/NuitonConfigExample.toml | 35 ++++ .../src/test/resources/NuitonConfigExample.yaml | 0 ...ationConfigFileNameNotInitializedException.java | 22 +++ .../org/nuiton/config/ApplicationConfigTest.java | 2 +- pom.xml | 6 + src/site/apt/index.apt | 6 +- src/site/apt/usage.apt.vm | 207 ++++++++++++--------- 25 files changed, 784 insertions(+), 390 deletions(-) create mode 100644 nuiton-config-example/src/main/config/NuitonConfigExample.toml rename nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.yml => nuiton-config-example/src/main/config/NuitonConfigExample.yaml (100%) create mode 100644 nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java copy nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/{templates/ApplicationConfigTransformerConfig.java => io/ConfigModelIO.java} (68%) create mode 100644 nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImpl.java rename nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/{model/ConfigModelUtil.java => io/ConfigModelIOYamlImpl.java} (64%) copy nuiton-config/src/main/java/org/nuiton/config/ApplicationConfigSaveException.java => nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ReadConfigModelException.java (71%) copy nuiton-config/src/main/java/org/nuiton/config/ApplicationConfigSaveException.java => nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/WriteConfigModelException.java (71%) create mode 100644 nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImplTest.java create mode 100644 nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java rename nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/{parser/yml/ConfigModelUtilTest.java => io/ConfigMoldeIOFixtures.java} (86%) create mode 100644 nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.toml rename nuiton-config-example/src/main/config/NuitonConfigExample.yml => nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.yaml (100%) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit ffc15bbc6d92f57e803bf077a5de437e146506fd Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 11:16:03 2016 +0200 Fix test beacuase printConfig has more than one implementations in ApplicationConfig class --- .../src/test/java/org/nuiton/config/ApplicationConfigTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuiton-config/src/test/java/org/nuiton/config/ApplicationConfigTest.java b/nuiton-config/src/test/java/org/nuiton/config/ApplicationConfigTest.java index 35d45e7..4180e4c 100644 --- a/nuiton-config/src/test/java/org/nuiton/config/ApplicationConfigTest.java +++ b/nuiton-config/src/test/java/org/nuiton/config/ApplicationConfigTest.java @@ -275,7 +275,7 @@ public class ApplicationConfigTest { public void doActionOnApplicationConfig() throws Exception { ApplicationConfig instance = new ApplicationConfig(); - instance.parse("--this#printConfig"); + instance.parse("--this#toString"); Map<Integer, List<Action>> actions = instance.actions; -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit a7df6b110d3a22f89a4dc617bc45a4f4963972c1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 13:44:21 2016 +0200 Support toml format for configuration description --- nuiton-config-maven-plugin/pom.xml | 18 +++++ .../org/nuiton/config/plugin/io/ConfigModelIO.java | 20 ++++++ .../config/plugin/io/ConfigModelIOTomlImpl.java | 56 +++++++++++++++ .../ConfigModelIOYamlImpl.java} | 34 ++++++---- .../config/plugin/io/ReadConfigModelException.java | 13 ++++ .../plugin/io/WriteConfigModelException.java | 13 ++++ .../plugin/io/ConfigModelIOTomlImplTest.java | 79 ++++++++++++++++++++++ .../plugin/io/ConfigModelIOYamlImplTest.java | 79 ++++++++++++++++++++++ .../ConfigMoldeIOFixtures.java} | 47 ++----------- .../src/test/resources/NuitonConfigExample.toml | 51 ++++++++++++++ pom.xml | 6 ++ 11 files changed, 362 insertions(+), 54 deletions(-) diff --git a/nuiton-config-maven-plugin/pom.xml b/nuiton-config-maven-plugin/pom.xml index da8758e..83b1d6e 100644 --- a/nuiton-config-maven-plugin/pom.xml +++ b/nuiton-config-maven-plugin/pom.xml @@ -164,6 +164,11 @@ </dependency> <dependency> + <groupId>com.moandjiezana.toml</groupId> + <artifactId>toml4j</artifactId> + </dependency> + + <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <scope>runtime</scope> @@ -217,6 +222,19 @@ </configuration> </plugin> + <!-- expose new plexus components --> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-metadata</artifactId> + <executions> + <execution> + <goals> + <goal>generate-metadata</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> </build> diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIO.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIO.java new file mode 100644 index 0000000..b323efc --- /dev/null +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIO.java @@ -0,0 +1,20 @@ +package org.nuiton.config.plugin.io; + +import org.nuiton.config.plugin.model.ConfigModel; + +import java.nio.file.Path; + +/** + * Perform IO operations on {@link ConfigModel}. + * + * Created on 02/10/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0 + */ +public interface ConfigModelIO { + + ConfigModel read(Path path) throws ReadConfigModelException; + + void write(ConfigModel model, Path path) throws WriteConfigModelException; +} diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImpl.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImpl.java new file mode 100644 index 0000000..aa4ccbc --- /dev/null +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImpl.java @@ -0,0 +1,56 @@ +package org.nuiton.config.plugin.io; + +import com.google.common.io.Files; +import com.moandjiezana.toml.Toml; +import com.moandjiezana.toml.TomlWriter; +import org.nuiton.config.plugin.model.ConfigModel; +import org.nuiton.config.plugin.model.OptionModel; + +import java.io.Reader; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; + +/** + * Implementation using {@code toml} format. + * + * Created on 02/10/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @plexus.component role="org.nuiton.config.plugin.io.ConfigModelIO" role-hint="toml" + * @since 3.0 + */ +public class ConfigModelIOTomlImpl implements ConfigModelIO { + + @Override + public ConfigModel read(Path path) throws ReadConfigModelException { + + try (Reader reader = Files.newReader(path.toFile(), StandardCharsets.UTF_8)) { + Toml toml = new Toml().read(reader); + ConfigModel configModel = toml.to(ConfigModel.class); + + // re-set the type to get real java class and not your alias + for (OptionModel optionModel : configModel.getOptions()) { + optionModel.setType(optionModel.getType()); + } + return configModel; + } catch (Exception e) { + throw new ReadConfigModelException("Can't real toml config model from file: " + path, e); + } + + } + + @Override + public void write(ConfigModel configModel, Path path) throws WriteConfigModelException { + + try (Writer writer = Files.newWriter(path.toFile(), StandardCharsets.UTF_8)) { + + new TomlWriter().write(configModel, writer); + + } catch (Exception e) { + throw new WriteConfigModelException("Can't write toml config model from file: " + path, e); + } + + } + +} diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/model/ConfigModelUtil.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImpl.java similarity index 64% rename from nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/model/ConfigModelUtil.java rename to nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImpl.java index a25a7ec..eb32d2b 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/model/ConfigModelUtil.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImpl.java @@ -1,4 +1,4 @@ -package org.nuiton.config.plugin.model; +package org.nuiton.config.plugin.io; /*- * #%L @@ -25,6 +25,9 @@ package org.nuiton.config.plugin.model; import com.esotericsoftware.yamlbeans.YamlConfig; import com.esotericsoftware.yamlbeans.YamlReader; import com.esotericsoftware.yamlbeans.YamlWriter; +import org.nuiton.config.plugin.model.ActionModel; +import org.nuiton.config.plugin.model.ConfigModel; +import org.nuiton.config.plugin.model.OptionModel; import java.io.Reader; import java.io.Writer; @@ -33,46 +36,51 @@ import java.nio.file.Files; import java.nio.file.Path; /** + * Implementation using {@code yaml} format. + * * Created on 01/10/16. * * @author Tony Chemit - chemit@codelutin.com + * @plexus.component role="org.nuiton.config.plugin.io.ConfigModelIO" role-hint="yml" * @since 3.0 */ -public class ConfigModelUtil { +public class ConfigModelIOYamlImpl implements ConfigModelIO { - public static ConfigModel read(Path file) { + @Override + public ConfigModel read(Path path) throws ReadConfigModelException { - try (Reader fileReader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { + try (Reader fileReader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { YamlReader reader = new YamlReader(fileReader, createConfig()); - return reader.read(ConfigModel.class); - + ConfigModel configModel = reader.read(ConfigModel.class); + return configModel; } catch (Exception e) { - throw new RuntimeException("Could not read config model from file: " + file, e); + throw new ReadConfigModelException("Can't real yaml config model from file: " + path, e); } + } - public static void write(ConfigModel configModel, Path file) { + @Override + public void write(ConfigModel configModel, Path path) throws WriteConfigModelException { - try (Writer fileWriter = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { + try (Writer fileWriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { YamlWriter writer = new YamlWriter(fileWriter, createConfig()); writer.write(configModel); fileWriter.flush(); writer.close(); } catch (Exception e) { - throw new RuntimeException("Could not write config model to file: " + file, e); + throw new WriteConfigModelException("Can't write yaml config model from file: " + path, e); } + } - private static YamlConfig createConfig() { + private YamlConfig createConfig() { YamlConfig yamlConfig = new YamlConfig(); yamlConfig.setClassTag("option", OptionModel.class); yamlConfig.setClassTag("action", ActionModel.class); yamlConfig.writeConfig.setIndentSize(2); yamlConfig.writeConfig.setWriteRootTags(false); -// yamlConfig.setPropertyElementType(OptionModel.class, "options", OptionModel.class); -// yamlConfig.setPropertyElementType(ActionModel.class, "actions", ActionModel.class); return yamlConfig; } diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ReadConfigModelException.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ReadConfigModelException.java new file mode 100644 index 0000000..6d50c19 --- /dev/null +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ReadConfigModelException.java @@ -0,0 +1,13 @@ +package org.nuiton.config.plugin.io; + +/** + * Created on 02/10/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0 + */ +public class ReadConfigModelException extends Exception { + public ReadConfigModelException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/WriteConfigModelException.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/WriteConfigModelException.java new file mode 100644 index 0000000..c6d0334 --- /dev/null +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/WriteConfigModelException.java @@ -0,0 +1,13 @@ +package org.nuiton.config.plugin.io; + +/** + * Created on 02/10/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0 + */ +public class WriteConfigModelException extends Exception { + public WriteConfigModelException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImplTest.java b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImplTest.java new file mode 100644 index 0000000..390f114 --- /dev/null +++ b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImplTest.java @@ -0,0 +1,79 @@ +package org.nuiton.config.plugin.io; + +/*- + * #%L + * Nuiton Config :: Maven plugin + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.config.plugin.model.ConfigModel; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Created on 01/10/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0 + */ +public class ConfigModelIOTomlImplTest { + + private ConfigModelIO io; + private ConfigMoldeIOFixtures ioFixtures; + + @Before + public void setUp() throws Exception { + io = new ConfigModelIOTomlImpl(); + ioFixtures = new ConfigMoldeIOFixtures(); + } + + @Test + public void read() throws Exception { + + Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.toml"); + + ConfigModel configModel = io.read(path); + + ioFixtures.assertConfigModel(configModel); + + } + + @Test + public void write() throws Exception { + + Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.toml"); + + + ConfigModel configModel = io.read(path); + Assert.assertNotNull(configModel); + + Path path2 = Paths.get(new File("").getAbsolutePath(), "target", "surefire-workdir", "NuitonConfigExample2.toml"); + io.write(configModel, path2); + + ConfigModel configModel2 = io.read(path); + ioFixtures.assertConfigModel(configModel2); + + } + +} diff --git a/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java new file mode 100644 index 0000000..531ba13 --- /dev/null +++ b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java @@ -0,0 +1,79 @@ +package org.nuiton.config.plugin.io; + +/*- + * #%L + * Nuiton Config :: Maven plugin + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.config.plugin.model.ConfigModel; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Created on 01/10/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0 + */ +public class ConfigModelIOYamlImplTest { + + private ConfigModelIO io; + private ConfigMoldeIOFixtures ioFixtures; + + @Before + public void setUp() throws Exception { + io = new ConfigModelIOYamlImpl(); + ioFixtures = new ConfigMoldeIOFixtures(); + } + + @Test + public void read() throws Exception { + + Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.yml"); + + ConfigModel configModel = io.read(path); + + ioFixtures.assertConfigModel(configModel); + + } + + @Test + public void write() throws Exception { + + Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.yml"); + + + ConfigModel configModel = io.read(path); + Assert.assertNotNull(configModel); + + Path path2 = Paths.get(new File("").getAbsolutePath(), "target", "surefire-workdir", "NuitonConfigExample2.yml"); + io.write(configModel, path2); + + ConfigModel configModel2 = io.read(path); + ioFixtures.assertConfigModel(configModel2); + + } + +} diff --git a/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/parser/yml/ConfigModelUtilTest.java b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigMoldeIOFixtures.java similarity index 66% rename from nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/parser/yml/ConfigModelUtilTest.java rename to nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigMoldeIOFixtures.java index b7bc295..6b11d7f 100644 --- a/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/parser/yml/ConfigModelUtilTest.java +++ b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigMoldeIOFixtures.java @@ -1,59 +1,27 @@ -package org.nuiton.config.plugin.parser.yml; - -/*- - * #%L - * Nuiton Config :: Maven plugin - * %% - * Copyright (C) 2016 Code Lutin, Tony Chemit - * %% - * 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 - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ +package org.nuiton.config.plugin.io; import org.junit.Assert; -import org.junit.Test; import org.nuiton.config.plugin.model.ActionModel; import org.nuiton.config.plugin.model.ConfigModel; -import org.nuiton.config.plugin.model.ConfigModelUtil; import org.nuiton.config.plugin.model.OptionModel; -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; /** - * Created by tchemit on 01/10/16. + * Created on 02/10/16. * * @author Tony Chemit - chemit@codelutin.com + * @since 3.0 */ -public class ConfigModelUtilTest { - - @Test - public void read() throws Exception { +class ConfigMoldeIOFixtures { - Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.yml"); - - ConfigModel configModel = ConfigModelUtil.read(path); + void assertConfigModel(ConfigModel configModel) { Assert.assertNotNull(configModel); Assert.assertEquals("Exemple de configuration", configModel.getDescription()); List<OptionModel> options = configModel.getOptions(); Assert.assertNotNull(options); Assert.assertEquals(5, options.size()); - assertOption(options.get(0), "identity.firstName", "Prénom de l'utilisateur", String.class, "Joshua"); assertOption(options.get(1), "identity.lastName", "Nom de l'utilisateur", String.class, "Bloch"); assertOption(options.get(2), "identity.email", "Courriel de l'utilisateur", String.class, null); @@ -64,13 +32,10 @@ public class ConfigModelUtilTest { Assert.assertNotNull(actions); Assert.assertEquals(1, actions.size()); assertAction(actions.get(0), "help", "Pour afficher l'aide", "org.nuiton.config.example.NuitonConfigExample#help", "-h", "--help"); - } private void assertOption(OptionModel optionModel, String expectedKey, String expectedDescpription, Class<?> expectedType, String expectedDefaultValue) { Assert.assertNotNull(optionModel); - Assert.assertNotNull(optionModel); - Assert.assertNotNull(optionModel.getKey()); Assert.assertEquals(expectedKey, optionModel.getKey()); Assert.assertNotNull(optionModel.getDescription()); @@ -82,7 +47,6 @@ public class ConfigModelUtilTest { private void assertAction(ActionModel actionModel, String expectedName, String expectedDescription, String expectedAction, String... expectedAliases) { Assert.assertNotNull(actionModel); - Assert.assertNotNull(actionModel.getName()); Assert.assertEquals(expectedName, actionModel.getName()); Assert.assertNotNull(actionModel.getDescription()); @@ -91,4 +55,5 @@ public class ConfigModelUtilTest { Assert.assertEquals(expectedAction, actionModel.getAction()); Assert.assertArrayEquals(expectedAliases, actionModel.getAliases()); } + } diff --git a/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.toml b/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.toml new file mode 100644 index 0000000..5c69a8c --- /dev/null +++ b/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.toml @@ -0,0 +1,51 @@ +description = "Exemple de configuration" + +[[options]] +name = "firstName" +key = "identity.firstName" +description = "Prénom de l'utilisateur" +type = "string" +defaultValue = "Joshua" +_transient = false +_final = false + +[[options]] +name = "lastName" +key = "identity.lastName" +description = "Nom de l'utilisateur" +type = "string" +defaultValue = "Bloch" +_transient = false +_final = false + +[[options]] +name = "email" +key = "identity.email" +description = "Courriel de l'utilisateur" +type = "string" +_transient = false +_final = false + +[[options]] +name = "twitter" +key = "identity.twitter" +description = "Compte Twitter de l'utilisateur" +type = "string" +defaultValue = "jbloch" +_transient = false +_final = false + +[[options]] +name = "age" +key = "identity.age" +description = "age de l'utilisateur" +type = "int" +defaultValue = "56" +_transient = false +_final = false + +[[actions]] +name = "help" +description = "Pour afficher l'aide" +action = "org.nuiton.config.example.NuitonConfigExample#help" +aliases = ["-h", "--help"] diff --git a/pom.xml b/pom.xml index 631497c..cc02e05 100644 --- a/pom.xml +++ b/pom.xml @@ -166,6 +166,12 @@ </dependency> <dependency> + <groupId>com.moandjiezana.toml</groupId> + <artifactId>toml4j</artifactId> + <version>0.7.1</version> + </dependency> + + <dependency> <groupId>com.esotericsoftware.yamlbeans</groupId> <artifactId>yamlbeans</artifactId> <!--Ne pas utiliser la version 1.09 elle est buggée--> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit a90f02f8ace46effe61440f4165c4ce7451ddf7a Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 13:44:51 2016 +0200 Improve mojo design --- .../nuiton/config/plugin/ConfigMojoSupport.java | 104 ++++++++++++++++++ .../org/nuiton/config/plugin/DescribeMojo.java | 94 +++++----------- .../org/nuiton/config/plugin/GenerateMojo.java | 119 +++++++-------------- .../src/main/resources/log4j.properties | 1 - 4 files changed, 167 insertions(+), 151 deletions(-) diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java new file mode 100644 index 0000000..b7a95f7 --- /dev/null +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java @@ -0,0 +1,104 @@ +package org.nuiton.config.plugin; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.nuiton.config.plugin.io.ConfigModelIO; +import org.nuiton.plugin.AbstractPlugin; +import org.nuiton.plugin.PluginHelper; + +import java.io.File; +import java.util.Map; + +/** + * Created on 02/10/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0 + */ +abstract class ConfigMojoSupport extends AbstractPlugin { + + /** + * Output format {@code toml} or {@code yml}. + * + * Default value is {@code toml}. + */ + @Parameter(property = "config.format", defaultValue = "toml") + private String format; + + /** + * The path of model file. + * + * <p>Default value is </p> + * <pre>${modelDirectory}/${modelName}.${format}</pre> + */ + @Parameter(property = "config.modelFile") + private File modelFile; + + /** + * The source directory where to scan model file. + */ + @Parameter(property = "config.modelDirectory", defaultValue = "${basedir}/src/main/config", required = true) + private File modelDirectory; + + /** + * Pour activer le mode verbeux. + */ + @Parameter(property = "config.verbose", defaultValue = "${maven.verbose}") + private boolean verbose; + + /** + * Maven project. + */ + @Parameter(defaultValue = "${project}", readonly = true) + private MavenProject project; + + @Component(role = ConfigModelIO.class) + private Map<String, ConfigModelIO> configModelIs; + + @Override + protected void init() throws Exception { + + if (!configModelIs.containsKey(format)) { + throw new MojoExecutionException("Don't know format: " + format + ", use one of these: " + configModelIs.keySet()); + } + + if (isVerbose()) { + getLog().info("Use format: " + format); + } + + } + + @Override + public boolean isVerbose() { + return verbose; + } + + @Override + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + @Override + public MavenProject getProject() { + return project; + } + + @Override + public void setProject(MavenProject project) { + this.project = project; + } + + void setModelFile(String name) { + modelFile = PluginHelper.getFile(modelDirectory, name + "." + format); + } + + ConfigModelIO getIO() { + return configModelIs.get(format); + } + + File getModelFile() { + return modelFile; + } +} diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/DescribeMojo.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/DescribeMojo.java index 23a84d7..8c86c17 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/DescribeMojo.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/DescribeMojo.java @@ -30,17 +30,13 @@ 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.apache.maven.project.MavenProject; import org.nuiton.config.ApplicationConfigHelper; import org.nuiton.config.ApplicationConfigProvider; import org.nuiton.config.ConfigActionDef; import org.nuiton.config.ConfigOptionDef; import org.nuiton.config.plugin.model.ActionModel; import org.nuiton.config.plugin.model.ConfigModel; -import org.nuiton.config.plugin.model.ConfigModelUtil; import org.nuiton.config.plugin.model.OptionModel; -import org.nuiton.plugin.AbstractPlugin; -import org.nuiton.plugin.PluginHelper; import java.io.File; import java.nio.file.Files; @@ -60,7 +56,7 @@ import java.util.Locale; */ @Mojo(name = "describe", requiresDirectInvocation = true, defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) @Execute(phase = LifecyclePhase.COMPILE) -public class DescribeMojo extends AbstractPlugin { +public class DescribeMojo extends ConfigMojoSupport { /** * The name of provider to describe. @@ -70,47 +66,16 @@ public class DescribeMojo extends AbstractPlugin { * * @see ApplicationConfigProvider */ - @Parameter(property = "config.providerName") + @Parameter(property = "providerName") private String providerName; - /** - * The path of model file. - * - * <p>Default value is </p> - * <pre>config.sourceDirectory/config.modelName.yml</pre> - */ - @Parameter(property = "config.modelFile") - private File modelFile; - - /** - * The source directory where to scan model file. - */ - @Parameter(property = "config.modelDirectory", defaultValue = "${basedir}/src/main/config", required = true) - private File modelDirectory; - - /** - * The source directory where to scan options java file. - */ - @Parameter(property = "config.sourceDirectory", defaultValue = "${project.build.outputDirectory}", required = true) - private File sourceDirectory; - - /** - * Pour activer le mode verbeux. - */ - @Parameter(property = "config.verbose", defaultValue = "${maven.verbose}") - private boolean verbose; - - /** - * Maven project. - */ - @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; - private ConfigModel configModel; @Override protected void init() throws Exception { + super.init(); + if (providerName == null) { List<String> artifactIdPaths = new ArrayList<>(); @@ -121,24 +86,33 @@ public class DescribeMojo extends AbstractPlugin { } - getLog().info("Use provider name: " + providerName); + if (isVerbose()) { + getLog().info("Use provider name: " + providerName); + } + ClassLoader loader = initClassLoader(getProject(), new File(getProject().getBuild().getOutputDirectory()), true, false, true, true, true); - ClassLoader loader = this.initClassLoader(getProject(), sourceDirectory, true, false, false, true, true); + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - ApplicationConfigProvider provider = ApplicationConfigHelper.getProvider(loader, providerName); + ApplicationConfigProvider provider; + try { + Thread.currentThread().setContextClassLoader(loader); + provider = ApplicationConfigHelper.getProvider(loader, providerName); + } finally { + Thread.currentThread().setContextClassLoader(contextClassLoader); + } if (provider == null) { throw new MojoExecutionException("Could not find provider with name: " + providerName); } String modelName = StringUtils.removeEnd(provider.getName(), "Config"); - getLog().info("Use model name: " + modelName); - - if (modelFile == null) { - modelFile = PluginHelper.getFile(modelDirectory, modelName + ".yml"); + if (isVerbose()) { + getLog().info("Use model name: " + modelName); } - - Files.createDirectories(modelFile.getParentFile().toPath()); + if (getModelFile() == null) { + setModelFile(modelName); + } + Files.createDirectories(getModelFile().getParentFile().toPath()); String description = provider.getDescription(Locale.FRANCE); @@ -162,30 +136,10 @@ public class DescribeMojo extends AbstractPlugin { @Override protected void doAction() throws Exception { - getLog().info("Generate file to: " + modelFile); + getLog().info("Generate file to: " + getModelFile()); - ConfigModelUtil.write(configModel, modelFile.toPath()); + getIO().write(configModel, getModelFile().toPath()); } - @Override - public boolean isVerbose() { - return verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public MavenProject getProject() { - return project; - } - - @Override - public void setProject(MavenProject project) { - this.project = project; - } - } diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/GenerateMojo.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/GenerateMojo.java index 7a31fe0..be5cd5b 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/GenerateMojo.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/GenerateMojo.java @@ -32,16 +32,13 @@ 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.apache.maven.project.MavenProject; import org.nuiton.config.ApplicationConfigProvider; import org.nuiton.config.plugin.model.ConfigModel; -import org.nuiton.config.plugin.model.ConfigModelUtil; import org.nuiton.config.plugin.templates.ApplicationConfigTransformer; import org.nuiton.config.plugin.templates.ApplicationConfigTransformerConfig; import org.nuiton.eugene.DefaultTemplateConfiguration; import org.nuiton.eugene.Template; import org.nuiton.eugene.models.object.xml.ObjectModelImpl; -import org.nuiton.plugin.AbstractPlugin; import org.nuiton.plugin.PluginHelper; import java.io.File; @@ -63,7 +60,7 @@ import static java.util.Arrays.asList; * @since 3.0 */ @Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) -public class GenerateMojo extends AbstractPlugin implements ApplicationConfigTransformerConfig { +public class GenerateMojo extends ConfigMojoSupport implements ApplicationConfigTransformerConfig { /** * To set the package fully qualified name of the generated class. @@ -122,21 +119,6 @@ public class GenerateMojo extends AbstractPlugin implements ApplicationConfigTra private boolean useNuitonI18n; /** - * The path of model file. - * - * <p>Default value is </p> - * <pre>config.sourceDirectory/config.modelName.yml</pre> - */ - @Parameter(property = "config.modelFile") - private File modelFile; - - /** - * The source directory where to scan model file. - */ - @Parameter(property = "config.modelDirectory", defaultValue = "${basedir}/src/main/config", required = true) - private File modelDirectory; - - /** * The source directory where to scan options java file. */ @Parameter(property = "config.sourceDirectory", defaultValue = "${basedir}/src/main/java", required = true) @@ -145,22 +127,8 @@ public class GenerateMojo extends AbstractPlugin implements ApplicationConfigTra /** * The root directory where to generated. */ - @Parameter(property = "config.outputdirectory", defaultValue = "${basedir}/target/generated-sources/java", required = true) - private File outputdirectory; - - /** - * Pour activer le mode verbeux. - */ - @Parameter(property = "config.verbose", defaultValue = "${maven.verbose}") - private boolean verbose; - - /** - * Maven project. - */ - @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; - - private ObjectModelImpl objectModel; + @Parameter(property = "config.outputDirectory", defaultValue = "${project.build.directory}/generated-sources/java", required = true) + private File outputDirectory; private ApplicationConfigTransformer template; private String configClassName; @@ -170,22 +138,25 @@ public class GenerateMojo extends AbstractPlugin implements ApplicationConfigTra @Override protected void init() throws Exception { + super.init(); + if (modelName == null) { List<String> artifactIdPaths = new ArrayList<>(); for (String artifactIdPath : Arrays.asList(getProject().getArtifactId().replaceAll("-", ".").split("\\."))) { artifactIdPaths.add(StringUtils.capitalize(artifactIdPath)); } modelName = Joiner.on("").join(artifactIdPaths); - getLog().info("Use objectModel name: " + modelName); - + if (isVerbose()) { + getLog().info("Use model name: " + modelName); + } } - if (modelFile == null) { - modelFile = new File(modelDirectory, modelName + ".yml"); + if (getModelFile() == null) { + setModelFile(modelName); } + File modelFile = getModelFile(); if (!modelFile.exists()) { - throw new MojoExecutionException("No model file found at: " + modelFile); } @@ -200,45 +171,48 @@ public class GenerateMojo extends AbstractPlugin implements ApplicationConfigTra groupIdPaths.addAll(artifactIdPaths); packageName = Joiner.on(".").join(groupIdPaths); - getLog().info("Use package name: " + packageName); + if (isVerbose()) { + getLog().info("Use package name: " + packageName); + } } if (optionsClassName == null) { optionsClassName = modelName + "ConfigOption"; - getLog().info("Configuration options class: " + optionsClassName); + if (isVerbose()) { + getLog().info("Configuration options class: " + optionsClassName); + } } if (actionsClassName == null) { actionsClassName = modelName + "ConfigAction"; - getLog().info("Configuration actions class: " + actionsClassName); - + if (isVerbose()) { + getLog().info("Configuration actions class: " + actionsClassName); + } } ClassLoader loader = this.initClassLoader(getProject(), sourceDirectory, true, false, false, true, true); // get options - objectModel = new ObjectModelImpl(); - objectModel.setName(modelName); - - configClassName = modelName + "Config"; getLog().info("Config class name: " + configClassName); if (generateProvider) { configProviderClassName = configClassName + "Provider"; - getLog().info("Config provider class name: " + configClassName); + if (isVerbose()) { + getLog().info("Config provider class name: " + configClassName); + } } - configModel = ConfigModelUtil.read(modelFile.toPath()); + configModel = getIO().read(modelFile.toPath()); Properties templateProperties = new Properties(); templateProperties.put(Template.PROP_ENCODING, StandardCharsets.UTF_8.name()); - templateProperties.put(Template.PROP_VERBOSE, verbose); + templateProperties.put(Template.PROP_VERBOSE, isVerbose()); templateProperties.put(Template.PROP_OVERWRITE, true); templateProperties.put(Template.PROP_CLASS_LOADER, loader); templateProperties.put(ApplicationConfigTransformer.PROP_CONFIG, this); @@ -246,56 +220,41 @@ public class GenerateMojo extends AbstractPlugin implements ApplicationConfigTra template = new ApplicationConfigTransformer(); template.setConfiguration(new DefaultTemplateConfiguration(templateProperties)); - if (!project.getCompileSourceRoots().contains(outputdirectory.getPath())) { + if (!getProject().getCompileSourceRoots().contains(outputDirectory.getPath())) { if (isVerbose()) { - getLog().info("Add compile source root : " + outputdirectory); + getLog().info("Add compile source root : " + outputDirectory); } - project.addCompileSourceRoot(outputdirectory.getPath()); + getProject().addCompileSourceRoot(outputDirectory.getPath()); } } @Override protected void doAction() throws Exception { - getLog().info("Generate file(s) to: " + outputdirectory); + getLog().info("Generate file(s) to: " + outputDirectory); + + ObjectModelImpl objectModel = new ObjectModelImpl(); + objectModel.setName(modelName); - template.applyTemplate(objectModel, outputdirectory); + template.applyTemplate(objectModel, outputDirectory); if (generateProvider) { String content = packageName + "." + configClassName + "Provider"; - File serviceLoaderFile = PluginHelper.getFile(outputdirectory, "META-INF", "services", ApplicationConfigProvider.class.getName()); + File serviceLoaderFile = PluginHelper.getFile(outputDirectory, "META-INF", "services", ApplicationConfigProvider.class.getName()); Files.createParentDirs(serviceLoaderFile); Files.write(content.getBytes(), serviceLoaderFile); - getLog().info("Generate serviceLoader provider file: " + serviceLoaderFile); + if (isVerbose()) { + getLog().info("Generate serviceLoader provider file: " + serviceLoaderFile); + } Resource resource = new Resource(); - resource.setDirectory(outputdirectory.getAbsolutePath()); + resource.setDirectory(outputDirectory.getAbsolutePath()); resource.setIncludes(Collections.singletonList("**/" + ApplicationConfigProvider.class.getName())); - project.addResource(resource); + getProject().addResource(resource); } } @Override - public boolean isVerbose() { - return verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public MavenProject getProject() { - return project; - } - - @Override - public void setProject(MavenProject project) { - this.project = project; - } - - @Override public String getPackageName() { return packageName; } diff --git a/nuiton-config-maven-plugin/src/main/resources/log4j.properties b/nuiton-config-maven-plugin/src/main/resources/log4j.properties index 61f28db..c592a7b 100644 --- a/nuiton-config-maven-plugin/src/main/resources/log4j.properties +++ b/nuiton-config-maven-plugin/src/main/resources/log4j.properties @@ -26,5 +26,4 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n # package level -log4j.logger.org.nuiton=INFO log4j.logger.org.nuiton.config=INFO -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit e6611a047d7178f077c7ce3ffcbde4b4c28efe5b Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 13:44:53 2016 +0200 Use toml format in example --- .../src/main/config/NuitonConfigExample.toml | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/nuiton-config-example/src/main/config/NuitonConfigExample.toml b/nuiton-config-example/src/main/config/NuitonConfigExample.toml new file mode 100644 index 0000000..5c69a8c --- /dev/null +++ b/nuiton-config-example/src/main/config/NuitonConfigExample.toml @@ -0,0 +1,51 @@ +description = "Exemple de configuration" + +[[options]] +name = "firstName" +key = "identity.firstName" +description = "Prénom de l'utilisateur" +type = "string" +defaultValue = "Joshua" +_transient = false +_final = false + +[[options]] +name = "lastName" +key = "identity.lastName" +description = "Nom de l'utilisateur" +type = "string" +defaultValue = "Bloch" +_transient = false +_final = false + +[[options]] +name = "email" +key = "identity.email" +description = "Courriel de l'utilisateur" +type = "string" +_transient = false +_final = false + +[[options]] +name = "twitter" +key = "identity.twitter" +description = "Compte Twitter de l'utilisateur" +type = "string" +defaultValue = "jbloch" +_transient = false +_final = false + +[[options]] +name = "age" +key = "identity.age" +description = "age de l'utilisateur" +type = "int" +defaultValue = "56" +_transient = false +_final = false + +[[actions]] +name = "help" +description = "Pour afficher l'aide" +action = "org.nuiton.config.example.NuitonConfigExample#help" +aliases = ["-h", "--help"] -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit 5ca0fe18e7bbe09525407cea01667998a10327de Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 13:50:12 2016 +0200 Add missing header files --- .../nuiton/config/plugin/ConfigMojoSupport.java | 22 ++++++++++++++++++++++ .../org/nuiton/config/plugin/io/ConfigModelIO.java | 22 ++++++++++++++++++++++ .../config/plugin/io/ConfigModelIOTomlImpl.java | 22 ++++++++++++++++++++++ .../config/plugin/io/ReadConfigModelException.java | 22 ++++++++++++++++++++++ .../plugin/io/WriteConfigModelException.java | 22 ++++++++++++++++++++++ .../config/plugin/io/ConfigMoldeIOFixtures.java | 22 ++++++++++++++++++++++ ...ationConfigFileNameNotInitializedException.java | 22 ++++++++++++++++++++++ 7 files changed, 154 insertions(+) diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java index b7a95f7..a18f167 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java @@ -1,5 +1,27 @@ package org.nuiton.config.plugin; +/*- + * #%L + * Nuiton Config :: Maven plugin + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIO.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIO.java index b323efc..e0ad5ed 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIO.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIO.java @@ -1,5 +1,27 @@ package org.nuiton.config.plugin.io; +/*- + * #%L + * Nuiton Config :: Maven plugin + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import org.nuiton.config.plugin.model.ConfigModel; import java.nio.file.Path; diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImpl.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImpl.java index aa4ccbc..53b2411 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImpl.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOTomlImpl.java @@ -1,5 +1,27 @@ package org.nuiton.config.plugin.io; +/*- + * #%L + * Nuiton Config :: Maven plugin + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import com.google.common.io.Files; import com.moandjiezana.toml.Toml; import com.moandjiezana.toml.TomlWriter; diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ReadConfigModelException.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ReadConfigModelException.java index 6d50c19..ee0e1c7 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ReadConfigModelException.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ReadConfigModelException.java @@ -1,5 +1,27 @@ package org.nuiton.config.plugin.io; +/*- + * #%L + * Nuiton Config :: Maven plugin + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + /** * Created on 02/10/16. * diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/WriteConfigModelException.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/WriteConfigModelException.java index c6d0334..2276eee 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/WriteConfigModelException.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/WriteConfigModelException.java @@ -1,5 +1,27 @@ package org.nuiton.config.plugin.io; +/*- + * #%L + * Nuiton Config :: Maven plugin + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + /** * Created on 02/10/16. * diff --git a/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigMoldeIOFixtures.java b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigMoldeIOFixtures.java index 6b11d7f..d85e2ab 100644 --- a/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigMoldeIOFixtures.java +++ b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigMoldeIOFixtures.java @@ -1,5 +1,27 @@ package org.nuiton.config.plugin.io; +/*- + * #%L + * Nuiton Config :: Maven plugin + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import org.junit.Assert; import org.nuiton.config.plugin.model.ActionModel; import org.nuiton.config.plugin.model.ConfigModel; diff --git a/nuiton-config/src/main/java/org/nuiton/config/ApplicationConfigFileNameNotInitializedException.java b/nuiton-config/src/main/java/org/nuiton/config/ApplicationConfigFileNameNotInitializedException.java index a2ace35..8587bd4 100644 --- a/nuiton-config/src/main/java/org/nuiton/config/ApplicationConfigFileNameNotInitializedException.java +++ b/nuiton-config/src/main/java/org/nuiton/config/ApplicationConfigFileNameNotInitializedException.java @@ -1,5 +1,27 @@ package org.nuiton.config; +/*- + * #%L + * Nuiton Config :: API + * %% + * Copyright (C) 2016 Code Lutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + /** * Thrown when the config file name is required (to perform save action) on ApplicationConfig and the config file * name is not found in configuration. -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit 050514097b86c9946ccb18162afe84360aae03cc Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 15:49:48 2016 +0200 Rename yml files to yaml --- .../src/main/config/NuitonConfigExample.yaml | 0 .../src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java | 2 +- .../java/org/nuiton/config/plugin/io/ConfigModelIOYamlImpl.java | 2 +- .../java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java | 6 +++--- .../src/test/resources/NuitonConfigExample.yaml | 0 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.yml b/nuiton-config-example/src/main/config/NuitonConfigExample.yaml similarity index 100% rename from nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.yml rename to nuiton-config-example/src/main/config/NuitonConfigExample.yaml diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java index a18f167..433f776 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/ConfigMojoSupport.java @@ -42,7 +42,7 @@ import java.util.Map; abstract class ConfigMojoSupport extends AbstractPlugin { /** - * Output format {@code toml} or {@code yml}. + * Configuration description format {@code toml} or {@code yaml}. * * Default value is {@code toml}. */ diff --git a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImpl.java b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImpl.java index eb32d2b..f63bcf7 100644 --- a/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImpl.java +++ b/nuiton-config-maven-plugin/src/main/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImpl.java @@ -41,7 +41,7 @@ import java.nio.file.Path; * Created on 01/10/16. * * @author Tony Chemit - chemit@codelutin.com - * @plexus.component role="org.nuiton.config.plugin.io.ConfigModelIO" role-hint="yml" + * @plexus.component role="org.nuiton.config.plugin.io.ConfigModelIO" role-hint="yaml" * @since 3.0 */ public class ConfigModelIOYamlImpl implements ConfigModelIO { diff --git a/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java index 531ba13..2363b85 100644 --- a/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java +++ b/nuiton-config-maven-plugin/src/test/java/org/nuiton/config/plugin/io/ConfigModelIOYamlImplTest.java @@ -51,7 +51,7 @@ public class ConfigModelIOYamlImplTest { @Test public void read() throws Exception { - Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.yml"); + Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.yaml"); ConfigModel configModel = io.read(path); @@ -62,13 +62,13 @@ public class ConfigModelIOYamlImplTest { @Test public void write() throws Exception { - Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.yml"); + Path path = Paths.get(new File("").getAbsolutePath(), "src", "test", "resources", "NuitonConfigExample.yaml"); ConfigModel configModel = io.read(path); Assert.assertNotNull(configModel); - Path path2 = Paths.get(new File("").getAbsolutePath(), "target", "surefire-workdir", "NuitonConfigExample2.yml"); + Path path2 = Paths.get(new File("").getAbsolutePath(), "target", "surefire-workdir", "NuitonConfigExample2.yaml"); io.write(configModel, path2); ConfigModel configModel2 = io.read(path); diff --git a/nuiton-config-example/src/main/config/NuitonConfigExample.yml b/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.yaml similarity index 100% rename from nuiton-config-example/src/main/config/NuitonConfigExample.yml rename to nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.yaml -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit c2e4dab27a6b3fc9aca9996c6e84e5a3e9b986b4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 15:50:19 2016 +0200 clean toml files --- .../src/main/config/NuitonConfigExample.toml | 14 -------------- .../src/test/resources/NuitonConfigExample.toml | 18 +----------------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/nuiton-config-example/src/main/config/NuitonConfigExample.toml b/nuiton-config-example/src/main/config/NuitonConfigExample.toml index 5c69a8c..c7b9968 100644 --- a/nuiton-config-example/src/main/config/NuitonConfigExample.toml +++ b/nuiton-config-example/src/main/config/NuitonConfigExample.toml @@ -6,43 +6,29 @@ key = "identity.firstName" description = "Prénom de l'utilisateur" type = "string" defaultValue = "Joshua" -_transient = false -_final = false - [[options]] name = "lastName" key = "identity.lastName" description = "Nom de l'utilisateur" type = "string" defaultValue = "Bloch" -_transient = false -_final = false - [[options]] name = "email" key = "identity.email" description = "Courriel de l'utilisateur" type = "string" -_transient = false -_final = false - [[options]] name = "twitter" key = "identity.twitter" description = "Compte Twitter de l'utilisateur" type = "string" defaultValue = "jbloch" -_transient = false -_final = false - [[options]] name = "age" key = "identity.age" description = "age de l'utilisateur" type = "int" defaultValue = "56" -_transient = false -_final = false [[actions]] name = "help" diff --git a/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.toml b/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.toml index 5c69a8c..f888468 100644 --- a/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.toml +++ b/nuiton-config-maven-plugin/src/test/resources/NuitonConfigExample.toml @@ -1,51 +1,35 @@ description = "Exemple de configuration" - [[options]] name = "firstName" key = "identity.firstName" description = "Prénom de l'utilisateur" type = "string" defaultValue = "Joshua" -_transient = false -_final = false - [[options]] name = "lastName" key = "identity.lastName" description = "Nom de l'utilisateur" type = "string" defaultValue = "Bloch" -_transient = false -_final = false - [[options]] name = "email" key = "identity.email" description = "Courriel de l'utilisateur" type = "string" -_transient = false -_final = false - [[options]] name = "twitter" key = "identity.twitter" description = "Compte Twitter de l'utilisateur" type = "string" defaultValue = "jbloch" -_transient = false -_final = false - [[options]] name = "age" key = "identity.age" description = "age de l'utilisateur" type = "int" defaultValue = "56" -_transient = false -_final = false - [[actions]] name = "help" description = "Pour afficher l'aide" action = "org.nuiton.config.example.NuitonConfigExample#help" -aliases = ["-h", "--help"] +aliases = ["-h", "--help"] \ No newline at end of file -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit ab3e1ca783da059be2d87cad6edd55d5d2749bcb Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 15:50:28 2016 +0200 improve doc --- nuiton-config-example/pom.xml | 37 ++++ nuiton-config-example/src/site/apt/index.apt.vm | 92 +++------- nuiton-config-maven-plugin/src/site/apt/index.apt | 4 +- src/site/apt/index.apt | 6 +- src/site/apt/usage.apt.vm | 207 ++++++++++++---------- 5 files changed, 184 insertions(+), 162 deletions(-) diff --git a/nuiton-config-example/pom.xml b/nuiton-config-example/pom.xml index 02f2d1b..1e2b4ad 100644 --- a/nuiton-config-example/pom.xml +++ b/nuiton-config-example/pom.xml @@ -93,6 +93,43 @@ <profiles> <profile> + <id>reporting</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>Copy files to site</id> + <phase>pre-site</phase> + <configuration> + <target> + <copy todir="${project.reporting.outputDirectory}/model" failonerror="true" overwrite="true"> + <fileset dir="src/main/config"> + <include name="*.toml"/> + <include name="*.yaml"/> + </fileset> + </copy> + </target> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + </profile> + + <profile> <id>assembly-profile</id> <activation> <property> diff --git a/nuiton-config-example/src/site/apt/index.apt.vm b/nuiton-config-example/src/site/apt/index.apt.vm index d2b3820..031f5aa 100644 --- a/nuiton-config-example/src/site/apt/index.apt.vm +++ b/nuiton-config-example/src/site/apt/index.apt.vm @@ -30,19 +30,19 @@ Utilisation Ce module est un exemple d'utilisation de <<nuiton-config>>. - Le principe est simple + Le principe est simple : - * Décrire la configuration dans un fichier au format simple ; + [[1]] Décrire la configuration dans un fichier texte ; - * Générer via le plugin maven le code java à partir de la description ; + [[2]] Générer via le plugin maven le code java à partir de la description ; - * Utiliser la classe java de configuration qui a été générée ; + [[3]] Utiliser la classe java de configuration qui a été générée ; - * Documenter votre configuration via le plugin de report. + [[4]] Documenter votre configuration via le plugin de report. [] - Vous pouvez télécharger les sources du projet {{{https://nexus.nuiton.org/nexus/service/local/artifact/maven/redirect?g=public&g=org.nuiton&a=nuiton-config-example&v=${project.version}&e=zip&c=full}ici}}. + Vous pouvez télécharger les sources du projet {{{https://nexus.nuiton.org/nexus/service/local/artifact/maven/redirect?r=public&g=org.nuiton&a=nuiton-config-example&v=${project.version}&e=zip&c=full}ici}}. Dans cet exemple, nous utilisations toutes les valeurs par défaut fournies par le plugin (ZéroConf). @@ -54,21 +54,21 @@ Utilisation <version>${project.version}</version> +------------------------------------------------ - En utilisant les conventions du projet, la classe de configuration se nommera <<org.nuiton.config.example.NuitonConfigExampleConfig>>. + En utilisant les conventions du plugin, la classe de configuration se nommera <<org.nuiton.config.example.NuitonConfigExampleConfig>>. * Décrire les options et les actions de la configuration Dans notre exemple, nous avons quatre options dans la configuration : - * <<lastName>> le nom de l'utilisateur + [[1]] <<lastName>> le nom de l'utilisateur - * <<firstName>> le prénom de passe de l'utilisateur + [[2]] <<firstName>> le prénom de passe de l'utilisateur - * <<email>> le courriel de l'utilisateur + [[3]] <<email>> le courriel de l'utilisateur - * <<twitter>> le compte twitter de l'utilisateur + [[4]] <<twitter>> le compte twitter de l'utilisateur - * <<age>> l'age de l'utilisateur + [[5]] <<age>> l'age de l'utilisateur [] @@ -78,50 +78,8 @@ Utilisation [] - Voici le fichier de description de cette configuration : - -+------------------------------------------------ -description: Exemple de configuration -options: - - !option - name: firstName - key: identity.firstName - type: string - description: Prénom de l'utilisateur - defaultValue: Joshua - - !option - name: lastName - key: identity.lastName - type: string - description: Nom de l'utilisateur - defaultValue: Bloch - - !option - name: email - key: identity.email - type: string - description: Courriel de l'utilisateur - - !option - name: twitter - key: identity.twitter - type: string - description: Compte Twitter de l'utilisateur - defaultValue: jbloch - - !option - name: age - key: identity.age - type: int - description: age de l'utilisateur - defaultValue: 56 -actions: - - !action - name: help - description: Pour afficher l'aide - action: org.nuiton.config.example.NuitonConfigExample#help - aliases: - - "-h" - - "--help" -+------------------------------------------------ - + Voir le fichier de configuration au format {{{./model/NuitonConfigExample.toml}Toml}} ou + {{{./model/NuitonConfigExample.yaml}Yaml}}. * Générer les classes de configuration @@ -130,7 +88,7 @@ actions: +------------------------------------------------ <plugin> <groupId>${project.groupId}</groupId> - <artifactId>${project.artifactId}</artifactId> + <artifactId>nuiton-config-maven-plugin</artifactId> <version>${project.version}</version> <executions> <execution> @@ -157,26 +115,26 @@ target └── example ├── GeneratedNuitonConfigExampleConfig.java (2) ├── GeneratedNuitonConfigExampleConfigProvider.java (3) - ├── NuitonConfigExampleConfig.java (4) +---------------------> ├── NuitonConfigExampleConfig.java (4) <---------------------------- ├── NuitonConfigExampleConfigAction.java (5) ├── NuitonConfigExampleConfigOption.java (6) └── NuitonConfigExampleConfigProvider.java (7) +------------------------------------------------ - * (1) fichier qui enregistre (en utilisant le mécanisme ServiceLoader), le provider de configuration généré + [[1]] fichier qui enregistre (en utilisant le mécanisme ServiceLoader), le provider de configuration généré - * (2) classe abstraite de configuration + [[2]] classe abstraite de configuration - * (3) classe abstraite de provider + [[3]] classe abstraite de provider - * <<(4) classe de configuration prête à l'emploi dans votre application>> + [[4]] * <<(classe de configuration prête à l'emploi dans votre application>> - * (5) classe qui décrit les actions + [[5]] classe qui décrit les actions - * (6) classe qui décrit les options + [[6]] classe qui décrit les options - * (5) provider de configuration prêt à l'emploi (il sert pour la génération de la documentation notamment) + [[7]] provider de configuration prêt à l'emploi (il sert pour la génération de la documentation notamment) [] @@ -192,7 +150,7 @@ target +------------------------------------------------ <plugin> <groupId>${project.groupId}</groupId> - <artifactId>${project.artifactId}</artifactId> + <artifactId>nuiton-config-maven-plugin</artifactId> <version>${project.version}</version> <reportSets> <reportSet> @@ -204,4 +162,4 @@ target </plugin> +------------------------------------------------ - Retrouver le rapport généré ({{{./config-report.html}ici}}). + ({{{./config-report.html}Voir rapport généré}}). diff --git a/nuiton-config-maven-plugin/src/site/apt/index.apt b/nuiton-config-maven-plugin/src/site/apt/index.apt index a1ecbab..4a35613 100644 --- a/nuiton-config-maven-plugin/src/site/apt/index.apt +++ b/nuiton-config-maven-plugin/src/site/apt/index.apt @@ -30,9 +30,9 @@ Présentation - Le plugin propose quatre goal : + Le plugin propose quatre goals : - * Goal {{{./generate-mojo.html/}generate}} : permet de générer les classes java de la configuration à partir d'un modèle de description ; + * Goal {{{./generate-mojo.html}generate}} : permet de générer les classes java de la configuration à partir d'un modèle de description ; * Goal {{{./describe-mojo.html}describe}} : permet de générer le modèle de description à partir des classes java de la configuration ; diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt index 8ca40ac..9d1d33c 100644 --- a/src/site/apt/index.apt +++ b/src/site/apt/index.apt @@ -32,7 +32,7 @@ Présentation * une api simple de gestion de configuration (voir {{{./nuiton-config/index.html}module API}}) ; - * un plugin maven pour générer la configuration et une documentation (voir {{{./nuiton-config-maven-plugin/index.html}module Maven}}) ; + * un plugin maven pour générer la configuration à partir de sa description textuelle et sa documentation (voir {{{./nuiton-config-maven-plugin/index.html}module Maven}}) ; * un projet exemple qui utilise <<nuiton-config>> (voir {{{./nuiton-config-example/index.html} module Exemple}}). @@ -43,9 +43,9 @@ Philosophie du projet Le but de ce projet est de fournir une manière simple et efficace de gérer une ou plusieurs configurations dans un projet Java. - Pour ce faire, on propose de décrire les options et actions d'une configuration dans un format simple et concis (yaml) + Pour ce faire, on propose de décrire la configuration dans un format textuel simple et concis (toml ou yaml). - Ensuite on utilise le plugin de génération fourni pour générer une classe de configuration prête à l'emploi. + Ensuite on utilise le plugin de génération fourni pour générer une classe Java de configuration prête à l'emploi. On peut aussi par la suite générer un rapport <maven> de documentation de la configuration. diff --git a/src/site/apt/usage.apt.vm b/src/site/apt/usage.apt.vm index 09e359c..97915fb 100644 --- a/src/site/apt/usage.apt.vm +++ b/src/site/apt/usage.apt.vm @@ -26,12 +26,32 @@ 2016-09-30 ---- -Décrire les options et les actions d'une configuration +Première étape : décrire sa configuration - Un format simple a été conçu pour décrire les options et actions d'une configuration. Il est base sur le format <<yaml>>. + La première chose à faire est de décrire sa configuration (options, actions, description, ...). + + Il existe deux formats ({{{https://github.com/toml-lang/toml}Toml}}) ou ({{{http://yaml.org/}Yaml}}) pour décrire la configuration. + + Le format par défaut est le <<Toml>>. + +* Comment décrire une configuration ? Une configuration est composée d'une description, d'options et d'actions (optionnelles) +** Format Toml + ++------------------------------------------------ +description = "Exemple de configuration" +[[options]] +[[options]] +... +[[actions]] +[[actions]] +... ++------------------------------------------------ + +** Format Yaml + +------------------------------------------------ description: Exemple de configuration options: @@ -44,19 +64,19 @@ actions: ... +------------------------------------------------ -* Comment décrire une option +* Comment décrire une option ? Une option contient les propriétés suivantes : - * <<name>> : [obligatoire] nom de l'option (dans la configuration générée, on pourra accéder à cette option via des getters/setters adaptés) ; + [[1]] <<name>> : [obligatoire] nom de l'option (dans la configuration générée, on pourra accéder à cette option via des getters/setters adaptés) ; - * <<key>> : [obligatoire] la clef de l'option à utiliser pour la sauvegarde dans le fichier de configuration ; + [[2]] <<key>> : [obligatoire] la clef de l'option à utiliser pour la sauvegarde dans le fichier de configuration ; - * <<type>> : [obligatoire] type de l'option (voir plus bas) ; + [[3]] <<type>> : [obligatoire] type de l'option (voir plus bas) ; - * <<description>> : [obligatoire] la description de l'option ou une clef i18n de traduction (si useNuitonI18n est activé) ; + [[4]] <<description>> : [obligatoire] la description de l'option ou une clef i18n de traduction (si useNuitonI18n est activé) ; - * <<defaultvalue>> : [optionnel] une valeur par défaut. + [[5]] <<defaultvalue>> : [optionnel] une valeur par défaut. [] @@ -68,29 +88,40 @@ actions: * les types primitifs (boolean, int, ...) et leur équivalents en objet (Boolean, Integer, ...) - * <<file>> : <<java.io.File>> + * <<file>> : <java.io.File> - * <<class>> : <<java.lang.Class>> + * <<class>> : <java.lang.Class> - * <<url>> : <<java.net.URL>> + * <<url>> : <java.net.URL> - * <<color>> : <<java.awt.Color>> + * <<color>> : <java.awt.Color> - * <<keystroke>> : <<javax.swing.KeyStroke>> + * <<keystroke>> : <javax.swing.KeyStroke> - * <<version>> : <<org.nuiton.version.Version>> + * <<version>> : <org.nuiton.version.Version> - * <<date>> : <<java.util.Date>> + * <<date>> : <java.util.Date> - * <<time>> : <<java.sql.Time>> + * <<time>> : <java.sql.Time> - * <<timestamp>> : <<java.sql.Timestamp>> + * <<timestamp>> : <java.sql.Timestamp> [] Pour pouvez aussi mettre n'importe quelle classe java qui dispose d'une constructeur publique via son nom qualifié. -** Exemple d'une option +** Exemple d'une option au format Toml + ++------------------------------------------------ +[[options]] +name = "age" +key = "identity.age" +description = "age de l'utilisateur" +type = "int" +defaultValue = "56" ++------------------------------------------------ + +** Exemple d'une option au format Yaml +------------------------------------------------ - !option @@ -101,21 +132,31 @@ actions: defaultValue: 56 +------------------------------------------------ -* Comment décrire une action +* Comment décrire une action ? Une action contient les propriétés suivantes : - * <<name>> : [obligatoire] nom de l'action ; + [[1]] <<name>> : [obligatoire] nom de l'action ; - * <<description>> : [obligatoire] la description de l'option ou une clef i18n de traduction (si useNuitonI18n est activé) ; + [[2]] <<description>> : [obligatoire] la description de l'option ou une clef i18n de traduction (si useNuitonI18n est activé) ; - * <<action>> : [obligatoire] l'action à executer ; + [[3]] <<action>> : [obligatoire] l'action à executer ; - * <<aliases>> : [optionnel] des alias pour activer l'action. + [[4]] <<aliases>> : [optionnel] des alias pour activer l'action. [] -** Exemple d'une action +** Exemple d'une action au format Toml + ++------------------------------------------------ +[[actions]] +name = "help" +description = "Pour afficher l'aide" +action = "org.nuiton.config.example.NuitonConfigExample#help" +aliases = ["-h", "--help"] ++------------------------------------------------ + +** Exemple d'une action au format Yaml +------------------------------------------------ - !action @@ -129,18 +170,17 @@ actions: * Exemple - Dans notre exemple, nous avons cinq options dans la configuration : - * <<lastName>> le nom de l'utilisateur + [[1]] <<lastName>> le nom de l'utilisateur - * <<firstName>> le prénom de passe de l'utilisateur + [[2]] <<firstName>> le prénom de passe de l'utilisateur - * <<email>> le courriel de l'utilisateur + [[3]] <<email>> le courriel de l'utilisateur - * <<twitter>> le compte twitter de l'utilisateur + [[4]] <<twitter>> le compte twitter de l'utilisateur - * <<age>> l'age de l'utilisateur + [[5]] <<age>> l'age de l'utilisateur [] @@ -150,53 +190,13 @@ actions: [] - Voici la description qui correspond : + Voir le fichier de configuration au format {{{./nuiton-config-example/model/NuitonConfigExample.toml}Toml}} ou + {{{./nuiton-config-example/model/NuitonConfigExample.yaml}Yaml}}. -+------------------------------------------------ -description: Exemple de configuration -options: - - !option - name: firstName - key: identity.firstName - type: string - description: Prénom de l'utilisateur - defaultValue: Joshua - - !option - name: lastName - key: identity.lastName - type: string - description: Nom de l'utilisateur - defaultValue: Bloch - - !option - name: email - key: identity.email - type: string - description: Courriel de l'utilisateur - - !option - name: twitter - key: identity.twitter - type: string - description: Compte Twitter de l'utilisateur - defaultValue: jbloch - - !option - name: age - key: identity.age - type: int - description: age de l'utilisateur - defaultValue: 56 -actions: - - !action - name: help - description: Pour afficher l'aide - action: org.nuiton.config.example.NuitonConfigExample#help - aliases: - - "-h" - - "--help" -+------------------------------------------------ +Deuxième étape : Générer la configuration -Générer la configuration - - Il suffit d'excuter le goal <<generate>> en lui indiquant le chemin de description de la configuration. + Il suffit d'excuter le goal {{{./nuiton-config-maven-plugin/generate-mojo.html}generate}} en lui indiquant + le chemin de description de la configuration. +------------------------------------------------ <plugin> @@ -213,19 +213,19 @@ Générer la configuration </plugin> +------------------------------------------------ + Le format par défaut utilisé est le <<Toml>>, vous pouvez aussi utiliser le format <<yaml>>. + Par défaut, on place le fichier de description dans le répertoire <<src/main/config>>. Si on ne précise pas de nom de modèle, le plugin utilise l'identifiant de l'artefact en le transformant au format «Camel Case». - Par exemple, si l'<artifactId> est <<nuiton-config-example>>, le nom de fichier est <<NuitonConfigExample.yml>> + Par exemple, si l'<artifactId> est <<nuiton-config-example>>, le nom de fichier est <<NuitonConfigExample.toml>> Si vous voulez utiliser un autre nom, ajouter la propriété de configuration <<modelName>>. - Pour plus de détails ce le plugin, consulter la page de {{{./generate-mojo.html/}détail}}. - * Utilisation de Nuiton-I18n - Il est possible d'utiliser {{{http://nuiton-i18n.nuiton.org/v/latest}Nuiton-I18n}} pour externaliser les descriptions + Il est possible d'utiliser {{{http://i18n.nuiton.org/v/latest}Nuiton-I18n}} pour externaliser les descriptions de la configuration, options et actions. Il suffit d'activer la propriété <<useNuitonI18n>> dans le plugin de génération. @@ -264,28 +264,29 @@ target +------------------------------------------------ - * (1) fichier qui enregistre (en utilisant le mécanisme ServiceLoader), le provider de configuration généré + [[1]] fichier qui enregistre (en utilisant le mécanisme ServiceLoader), le provider de configuration généré - * (2) classe abstraite de configuration + [[2]] classe abstraite de configuration - * (3) classe abstraite de provider + [[3]] classe abstraite de provider - * <<(4) La classe de configuration prête à l'emploi dans votre application>> + [[4]] <<classe de configuration prête à l'emploi dans votre application>> - * (5) classe qui décrit les actions + [[5]] classe qui décrit les actions - * (6) classe qui décrit les options + [[6]] classe qui décrit les options - * (5) provider de configuration prêt à l'emploi (il sert pour la génération de la documentation notamment) + [[7]] provider de configuration prêt à l'emploi (il sert pour la génération de la documentation notamment) [] <« Et Voila ! »>, vous pouvez utiliser votre configuration en Java. -Pour générer la documentation de votre configuration +Troisième étape : générer la documentation de votre configuration - Utiliser le mojo de report <<report>> ou <<aggregate-report>> pour générer la documentation sur les configurations - détectées via les providers. + Utiliser le mojo de report {{{./nuiton-config-maven-plugin/report-mojo.html}report}} ou + {{{./nuiton-config-maven-plugin/aggregate-report-mojo.html}aggregate-report}} pour générer la documentation + sur les configurations détectées via les providers. +------------------------------------------------ <plugin> @@ -302,4 +303,30 @@ Pour générer la documentation de votre configuration </plugin> +------------------------------------------------ - {{{./nuiton-config-example/config-report.html}Retrouver un exemple de rapport généré }}. + {{{./nuiton-config-example/config-report.html}Exemple de rapport généré}}. + +Décrire une configuration à partir des classes java (migration) + + Il est possible facilement de convertir des classes java de configuration en fichier de description (ensuite il suffit + alors de supprimer les classes java et de les générer iva le plugin). + + Pour cela il faut utiliser le goal {{{./nuiton-config-maven-plugin/describe-mojo.html}describe}}. + + Il faut au préalable que vous ayez défini un <provider> de configuration (Voir ApplicationConfigProvider TODO). + + Lancer ensuite en ligne de commande + ++------------------------------------------------ +mvn nuiton-config:describe -Dconfig.providerName=NuitonConfigExample ++------------------------------------------------ + + Cela va générer le fichier (toml) à l'emplacement suivant : + ++------------------------------------------------ +src +└── main + └── config + └── NuitonConfigExample.toml ++------------------------------------------------ + + Vous pouvez aussi choisir le format <Yaml> en passant l'option <<-Dconfig.format=yaml>>. -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-config. See https://gitlab.nuiton.org/nuiton/nuiton-config.git commit 5ba6f85230e2836134735f5246235173fbd243fd Merge: ffc15bb ab3e1ca Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Oct 2 15:50:40 2016 +0200 Use Toml format to describe configuration (Fixes #4056) Merge branch 'feature/4056' into develop nuiton-config-example/pom.xml | 37 ++++ .../src/main/config/NuitonConfigExample.toml | 37 ++++ .../src/main/config/NuitonConfigExample.yaml | 0 nuiton-config-example/src/site/apt/index.apt.vm | 92 +++------ nuiton-config-maven-plugin/pom.xml | 18 ++ .../nuiton/config/plugin/ConfigMojoSupport.java | 126 +++++++++++++ .../org/nuiton/config/plugin/DescribeMojo.java | 94 +++------- .../org/nuiton/config/plugin/GenerateMojo.java | 119 ++++-------- .../org/nuiton/config/plugin/io/ConfigModelIO.java | 42 +++++ .../config/plugin/io/ConfigModelIOTomlImpl.java | 78 ++++++++ .../ConfigModelIOYamlImpl.java} | 34 ++-- .../config/plugin/io/ReadConfigModelException.java | 35 ++++ .../plugin/io/WriteConfigModelException.java | 35 ++++ .../src/main/resources/log4j.properties | 1 - nuiton-config-maven-plugin/src/site/apt/index.apt | 4 +- .../plugin/io/ConfigModelIOTomlImplTest.java | 79 ++++++++ .../plugin/io/ConfigModelIOYamlImplTest.java | 79 ++++++++ .../ConfigMoldeIOFixtures.java} | 25 +-- .../src/test/resources/NuitonConfigExample.toml | 35 ++++ .../src/test/resources/NuitonConfigExample.yaml | 0 ...ationConfigFileNameNotInitializedException.java | 22 +++ pom.xml | 6 + src/site/apt/index.apt | 6 +- src/site/apt/usage.apt.vm | 207 ++++++++++++--------- 24 files changed, 866 insertions(+), 345 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm