Author: tchemit Date: 2012-05-01 12:45:30 +0200 (Tue, 01 May 2012) New Revision: 2323 Url: http://nuiton.org/repositories/revision/nuiton-utils/2323 Log: fixes #2063: Introduce a new module nuiton-utils-maven-report-plugin to offers some report on usefull classes fixes #2064: Add a ApplicationConfig report Added: trunk/nuiton-util-maven-report-plugin/ trunk/nuiton-util-maven-report-plugin/LICENSE.txt trunk/nuiton-util-maven-report-plugin/README.txt trunk/nuiton-util-maven-report-plugin/changelog.txt trunk/nuiton-util-maven-report-plugin/pom.xml trunk/nuiton-util-maven-report-plugin/src/ trunk/nuiton-util-maven-report-plugin/src/main/ trunk/nuiton-util-maven-report-plugin/src/main/java/ trunk/nuiton-util-maven-report-plugin/src/main/java/org/ trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/ trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/ trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/ trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReport.java trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReportRenderer.java trunk/nuiton-util-maven-report-plugin/src/main/resources/ trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report.properties trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_en.properties trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_fr.properties trunk/nuiton-util-maven-report-plugin/src/site/ trunk/nuiton-util-maven-report-plugin/src/site/rst/ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigProvider.java Property changes on: trunk/nuiton-util-maven-report-plugin ___________________________________________________________________ Added: svn:ignore + target *.ipr *.iws *.iml .idea Property changes on: trunk/nuiton-util-maven-report-plugin/LICENSE.txt ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Property changes on: trunk/nuiton-util-maven-report-plugin/README.txt ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Property changes on: trunk/nuiton-util-maven-report-plugin/changelog.txt ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-util-maven-report-plugin/pom.xml =================================================================== --- trunk/nuiton-util-maven-report-plugin/pom.xml (rev 0) +++ trunk/nuiton-util-maven-report-plugin/pom.xml 2012-05-01 10:45:30 UTC (rev 2323) @@ -0,0 +1,222 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + Nuiton Utils :: Nuiton Validator + $Id$ + $HeadURL$ + %% + Copyright (C) 2011 CodeLutin, 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% + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils-parent</artifactId> + <version>2.4.8-SNAPSHOT</version> + </parent> + + <artifactId>nuiton-util-maven-report-plugin</artifactId> + + <packaging>maven-plugin</packaging> + <dependencies> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>nuiton-utils</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-settings</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven.reporting</groupId> + <artifactId>maven-reporting-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.maven.reporting</groupId> + <artifactId>maven-reporting-impl</artifactId> + </dependency> + + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-i18n</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-core</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-site-renderer</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-decoration-model</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-sink-api</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + + <dependency> + <groupId>org.nuiton.i18n</groupId> + <artifactId>nuiton-i18n</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>provided</scope> + </dependency> + + </dependencies> + + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + + <name>Nuiton Utils :: Nuiton Maven Report Plugin</name> + <description>Some nice maven reports for api of nuiton-util.</description> + <inceptionYear>2012</inceptionYear> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <properties> + + </properties> + + <build> + + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>l10n-maven-plugin</artifactId> + <version>1.0-alpha-2</version> + <configuration> + <locales> + <locale>fr</locale> + </locales> + </configuration> + <executions> + <execution> + <goals> + <goal>pseudo</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <!-- ************************************************************* --> + <!-- *** Build Environment ************************************** --> + <!-- ************************************************************* --> + + <profiles> + + <profile> + <id>reporting</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + + <reporting> + <plugins> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <quiet>true</quiet> + <links> + <link>http://java.sun.com/javase/6/docs/api/</link> + </links> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>l10n-maven-plugin</artifactId> + <version>1.0-alpha-2</version> + <configuration> + <locales> + <locale>fr</locale> + </locales> + </configuration> + </plugin> + </plugins> + </reporting> + + </profile> + + </profiles> + +</project> Property changes on: trunk/nuiton-util-maven-report-plugin/pom.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReport.java =================================================================== --- trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReport.java (rev 0) +++ trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReport.java 2012-05-01 10:45:30 UTC (rev 2323) @@ -0,0 +1,351 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Maven Report Plugin + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 CodeLutin + * %% + * 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.util.plugin.report; + +import org.apache.maven.doxia.siterenderer.Renderer; +import org.apache.maven.project.MavenProject; +import org.apache.maven.reporting.AbstractMavenReport; +import org.apache.maven.reporting.MavenReportException; +import org.codehaus.plexus.i18n.I18N; +import org.codehaus.plexus.util.StringUtils; +import org.nuiton.i18n.I18n; +import org.nuiton.i18n.init.ClassPathI18nInitializer; +import org.nuiton.i18n.init.DefaultI18nInitializer; +import org.nuiton.i18n.init.I18nInitializer; +import org.nuiton.util.ApplicationConfigProvider; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.ServiceLoader; +import java.util.Set; + +/** + * Generates a report for declarated application config via the + * {@link ApplicationConfigProvider} mecanism. + * <p/> + * For each configuration, you can find all his options and actions. + * + * @author tchemit <chemit@codelutin.com> + * @goal application-config-report + * @requiresDependencyResolution runtime + * @requiresProject true + * @since 2.4.8 + */ +public class ApplicationConfigReport extends AbstractMavenReport { + + /** + * Report output directory. Note that this parameter is only relevant if the goal is run from the command line or + * from the default build lifecycle. If the goal is run indirectly as part of a site generation, the output + * directory configured in the Maven Site Plugin is used instead. + * + * @parameter default-value="${project.reporting.outputDirectory}" + * @required + * @since 2.4.8 + */ + private File outputDirectory; + + /** + * Report output encoding. Note that this parameter is only relevant if the goal is run from the command line or + * from the default build lifecycle. If the goal is run indirectly as part of a site generation, the output + * encoding configured in the Maven Site Plugin is used instead. + * + * @parameter expression="${outputEncoding}" default-value="${project.reporting.outputEncoding}" + * @required + * @since 2.4.8 + */ + private String outputEncoding; + + /** + * List of application config to include in report (separated by comma). + * <p/> + * <strong>Note:</strong> If not filled then will use all config found in class-path. + * + * @parameter expression="${config.include}" + * @since 2.4.8 + */ + private String include; + + /** + * List of application config to exclude from report (separated by comma). + * <p/> + * <strong>Note:</strong> If not filled no config will be exclude. + * + * @parameter expression="${config.exclude}" + * @since 2.4.8 + */ + private String exclude; + + /** + * Flag to activate verbose mode. + * <p/> + * <b>Note:</b> Verbose mode is always on if you starts a debug maven instance + * (says via {@code -X}). + * + * @parameter expression="${config.verbose}" default-value="${maven.verbose}" + * @since 2.4.8 + */ + private boolean verbose; + + /** + * Flag to render option in detail (add a section for each option). + * + * @parameter expression="${config.showOptionDetail}" default-value="true" + * @since 2.4.8 + */ + private boolean showOptionDetail; + /** + * Skip to generate the report. + * + * @parameter expression="${config.skip}" + * @since 2.4.8 + */ + private boolean skip; + + /** + * Optional i18n bundle name as used by the nuiton I18n system to init his + * files. + * <p/> + * If not given, will look at all i18n files in all over class-path (which + * could be costy if many dependencies), otherwise will init I18n system + * usinga {@link DefaultI18nInitializer} with this bundle name. + * + * @parameter expression="${config.i18nBundleName}" + * @since 2.4.8 + */ + private String i18nBundleName; + + /** + * The Maven Project. + * + * @parameter expression="${project}" + * @required + * @readonly + * @since 2.4.8 + */ + private MavenProject project; + + + /** + * List of all class path elements. + * + * @parameter default-value="${project.compileClasspathElements}" + * @required + * @readonly + * @since 2.4.8 + */ + private List<String> compileClasspathElements; + + /** + * Doxia Site Renderer. + * + * @component + * @since 2.4.8 + */ + private Renderer siteRenderer; + + /** + * Internationalization. + * + * @component + * @since 2.4.8 + */ + private I18N i18n; + + /** + * Class loader with all compile dependencies of the module in class-path + * (used to init i18n) and obtain config provider over compile class-path. + * + * @since 2.4.8 + */ + private ClassLoader newClassLoader; + + /** + * Set of ApplicationconfigProvider detected from configuration. + * + * @since 2.4.8 + */ + private Set<ApplicationConfigProvider> configProviders; + + @Override + public String getOutputName() { + return "application-config-report"; + } + + public String getDescription(Locale locale) { + return i18n.getString(getOutputName(), locale, "report.description"); + } + + public String getName(Locale locale) { + return i18n.getString(getOutputName(), locale, "report.title"); + } + + @Override + public String getCategoryName() { + return CATEGORY_PROJECT_REPORTS; + } + + @Override + public boolean canGenerateReport() { + return !skip; + } + + @Override + protected Renderer getSiteRenderer() { + return siteRenderer; + } + + @Override + protected String getOutputDirectory() { + return outputDirectory.getAbsolutePath(); + } + + @Override + protected MavenProject getProject() { + return project; + } + + @Override + protected void executeReport(Locale locale) throws MavenReportException { + + if (newClassLoader == null) { + + // not init + init(locale); + } else { + + // just change init language + I18n.setDefaultLocale(locale); + } + ApplicationConfigReportRenderer renderer = + new ApplicationConfigReportRenderer(getSink(), + i18n, + locale, + getOutputName(), + configProviders, + showOptionDetail); + renderer.render(); + } + + protected void init(Locale locale) { + if (getLog().isDebugEnabled()) { + + // debug mode set verbose flag to true + verbose = true; + } + + if (newClassLoader == null) { + List<URL> urls = new ArrayList<URL>(); + + for (String fileName : compileClasspathElements) { + File pathElem = new File(fileName); + try { + URL url = pathElem.toURI().toURL(); + urls.add(url); + getLog().debug("Added classpathElement URL " + url); + } catch (MalformedURLException e) { + throw new RuntimeException( + "Error in adding the classpath " + pathElem, e); + } + } + + newClassLoader = new URLClassLoader( + urls.toArray(new URL[urls.size()]), + Thread.currentThread().getContextClassLoader()); + } + + // get i18n initializer + I18nInitializer initializer; + if (StringUtils.isNotEmpty(i18nBundleName)) { + initializer = new DefaultI18nInitializer(i18nBundleName, + newClassLoader); + } else { + initializer = new ClassPathI18nInitializer(newClassLoader); + } + // init i18n + I18n.init(initializer, locale); + + // propagate extended classloader +// Thread.currentThread().setContextClassLoader(newClassLoader); + + if (configProviders == null) { + configProviders = new HashSet<ApplicationConfigProvider>(); + + Set<String> includes = null; + if (StringUtils.isNotEmpty(include)) { + includes = new HashSet<String>(Arrays.asList(include.split("\\s*,\\s*"))); + if (verbose) { + getLog().info("config - includes : " + includes); + } + } + + Set<String> excludes = null; + if (StringUtils.isNotEmpty(exclude)) { + excludes = new HashSet<String>(Arrays.asList(exclude.split("\\s*,\\s*"))); + if (verbose) { + getLog().info("config - excludes : " + excludes); + } + } + + ServiceLoader<ApplicationConfigProvider> loader = + ServiceLoader.load(ApplicationConfigProvider.class, + newClassLoader); + + for (ApplicationConfigProvider configProvider : loader) { + String name = configProvider.getName(); + if (includes != null && !includes.contains(name)) { + + // reject by include + if (verbose) { + getLog().info("configuration named '" + name + + "' is rejected by includes."); + } + continue; + } + if (excludes != null && excludes.contains(name)) { + + // reject by exclude + if (verbose) { + getLog().info("configuration named '" + name + + "' is rejected by excludes."); + } + continue; + } + if (verbose) { + getLog().info("configuration named '" + name + + "' will be generated."); + } + configProviders.add(configProvider); + } + } + } + +} Property changes on: trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReport.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReportRenderer.java =================================================================== --- trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReportRenderer.java (rev 0) +++ trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReportRenderer.java 2012-05-01 10:45:30 UTC (rev 2323) @@ -0,0 +1,478 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Maven Report Plugin + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 CodeLutin + * %% + * 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.util.plugin.report; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.maven.doxia.sink.Sink; +import org.apache.maven.doxia.sink.SinkEventAttributeSet; +import org.apache.maven.reporting.AbstractMavenReportRenderer; +import org.codehaus.plexus.i18n.I18N; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ApplicationConfigProvider; + +import java.util.Arrays; +import java.util.Locale; +import java.util.Set; + +import static org.nuiton.i18n.I18n.l_; + +/** + * Render the {@link ApplicationConfigReport} report. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.4.8 + */ +public class ApplicationConfigReportRenderer extends AbstractMavenReportRenderer { + + /** + * Internationalization component. + * + * @since 2.4.8 + */ + protected final I18N i18n; + + /** + * The locale we are rendering for. + * + * @since 2.4.8 + */ + protected final Locale locale; + + /** + * The name of the bundle containing our I18n resources. + * + * @since 2.4.8 + */ + protected final String bundleName; + + /** + * Set of config providers to generate. + * + * @since 2.4.8 + */ + protected final Set<ApplicationConfigProvider> configProviders; + + + /** + * To show option in detail. + * + * @since 2.4.8 + */ + protected final boolean optionWithDetail; + + public ApplicationConfigReportRenderer(Sink sink, + I18N i18n, + Locale locale, + String bundleName, + Set<ApplicationConfigProvider> configProviders, + boolean optionWithDetail) { + super(sink); + this.i18n = i18n; + this.locale = locale; + this.bundleName = bundleName; + this.sink = sink; + this.configProviders = configProviders; + this.optionWithDetail = optionWithDetail; + } + + @Override + public String getTitle() { + return getText("report.title"); + } + + @Override + public void renderBody() { + + sink.section1(); + sink.sectionTitle1(); + sink.text(getText("report.overview.title")); + sink.sectionTitle1_(); + sink.paragraph(); + sink.lineBreak(); + sink.text(getText("report.overview.text")); + sink.paragraph_(); + sink.lineBreak(); + + renderProviderSummaryTable(); + + sink.section1_(); + + if (CollectionUtils.isNotEmpty(configProviders)) { + + sink.section1(); + sink.sectionTitle1(); + sink.text(getText("report.detail.title")); + sink.sectionTitle1_(); + sink.lineBreak(); + sink.paragraph(); + sink.text(getText("report.detail.text")); + sink.paragraph_(); + + for (ApplicationConfigProvider configProvider : configProviders) { + + renderConfigProviderDetail(configProvider); + } + + sink.section1_(); + } + } + + private void renderProviderSummaryTable() { + + if (CollectionUtils.isEmpty(configProviders)) { + + sink.text(getText("report.detail.text.noConfig")); + + } else { + sink.table(); + + sink.tableRow(); + sinkHeaderCellText(getText("report.config.name")); + sinkHeaderCellText(getText("report.config.description")); + sinkHeaderCellText(getText("report.config.nbOptions")); + sinkHeaderCellText(getText("report.config.nbActions")); + sink.tableRow_(); + + for (ApplicationConfigProvider configProvider : configProviders) { + + sink.tableRow(); + sinkCellLink(configProvider.getName(), "./application-config-report.html#detail_" + configProvider.getName()); + sinkCellText(configProvider.getDescription(locale)); + sinkCellText(configProvider.getOptions().length + ""); + sinkCellText(configProvider.getActions().length + ""); + sink.tableRow_(); + } + sink.table_(); + } + } + + private void renderConfigProviderDetail(ApplicationConfigProvider configProvider) { + + sink.section2(); + sink.sectionTitle2(); + sink.anchor("detail_" + configProvider.getName()); + sink.text(getText("report.detail.configuration.title") + " " + + configProvider.getName()); + sink.anchor_(); + sink.sectionTitle2_(); + + sink.lineBreak(); + sink.paragraph(); + sink.text(getText("report.config.name") + " : "); + sink.bold(); + sink.text(configProvider.getName()); + sink.bold_(); + sink.paragraph_(); + + sink.lineBreak(); + sink.paragraph(); + sink.text(getText("report.config.description") + " : "); + sink.bold(); + sink.text(configProvider.getDescription(locale)); + sink.bold_(); + sink.paragraph_(); + + sink.section3(); + sink.sectionTitle3(); + sink.anchor("detail_options_" + configProvider.getName()); + + sink.text(getText("report.detail.options.title")); + sink.anchor_(); + sink.sectionTitle3_(); + sink.lineBreak(); + + ApplicationConfig.OptionDef[] options = configProvider.getOptions(); + + renderOptionDefsTable(configProvider, options); + + if (optionWithDetail) { + + for (ApplicationConfig.OptionDef option : options) { + + renderProviderOptionDetail(configProvider, option); + } + } + + sink.section3_(); + + sink.section3(); + sink.sectionTitle3(); + sink.text(getText("report.detail.actions.title")); + sink.sectionTitle3_(); + sink.lineBreak(); + + renderActionDefsTable(configProvider.getActions()); + + sink.section3_(); + + sink.section2_(); + } + + protected void renderOptionDefsTable(ApplicationConfigProvider configProvider, + ApplicationConfig.OptionDef[] options) { + + if (options.length == 0) { + + sink.paragraph(); + sink.bold(); + sink.text(getText("report.detail.options.noOptions")); + sink.bold_(); + sink.paragraph_(); + + } else { + + sink.table(); + sink.tableRow(); + + sinkHeaderCellText(getText("report.config.option.key")); + sinkHeaderCellText(getText("report.config.option.description")); + if (!optionWithDetail) { + sinkHeaderCellText(getText("report.config.option.type")); + } + sinkHeaderCellText(getText("report.config.option.defaultValue")); + + if (!optionWithDetail) { + sinkHeaderCellText(getText("report.config.option.final")); + sinkHeaderCellText(getText("report.config.option.transient")); + } + sink.tableRow_(); + + for (ApplicationConfig.OptionDef option : options) { + + sink.tableRow(); + if (optionWithDetail) { + sinkCellLink( + option.getKey(), + "./application-config-report.html#detail_" + + configProvider.getName() + "_" + option.getKey()); + } else { + sinkCellText(option.getKey()); + } + sinkCellText(l_(locale, option.getDescription())); + if (!optionWithDetail) { + sinkCellText(option.getType().getName()); + } + sinkCellVerbatimText(option.getDefaultValue()); + if (!optionWithDetail) { + sinkCellText(getText(option.isFinal())); + sinkCellText(getText(option.isTransient())); + } + sink.tableRow_(); + } + + sink.table_(); + + } + } + + protected void renderActionDefsTable(ApplicationConfig.ActionDef[] actions) { + + if (actions.length == 0) { + + sink.paragraph(); + sink.bold(); + sink.text(getText("report.detail.actions.noActions")); + sink.bold_(); + sink.paragraph_(); + + } else { + + sink.table(); + + sink.tableRow(); + sinkHeaderCellText(getText("report.config.action.action")); + sinkHeaderCellText(getText("report.config.action.aliases")); + sink.tableRow_(); + + for (ApplicationConfig.ActionDef action : actions) { + sink.tableRow(); + sinkCellText(action.getAction()); + sinkCellText(l_(locale, Arrays.toString(action.getAliases()))); + sink.tableRow_(); + } + + sink.table_(); + } + } + + private void renderProviderOptionDetail(ApplicationConfigProvider configProvider, + ApplicationConfig.OptionDef option) { + + final String cellWidth = "80%"; + final String headerWidth = "20%"; + + sink.section4(); + sink.sectionTitle4(); + sink.anchor("detail_" + configProvider.getName() + "_" + option.getKey()); + sink.text(getText("report.config.option.detail") + " " + option.getKey()); + sink.sectionTitle4_(); + sink.lineBreak(); + + sink.table(); + sink.tableRows(new int[]{Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT}, false); + + sink.tableRow(); + sinkHeaderCellText(headerWidth, getText("report.config.option.key")); + sink.tableCell(cellWidth); + sink.nonBreakingSpace(); + sink.bold(); + sink.text(option.getKey()); + sink.bold_(); + sink.tableCell_(); + sink.tableRow_(); + + sink.tableRow(); + sinkHeaderCellText(headerWidth, getText("report.config.option.description")); + sink.tableCell(cellWidth); + sink.nonBreakingSpace(); + sink.text(option.getDescription()); + sink.tableCell_(); + sink.tableRow_(); + + sink.tableRow(); + sinkHeaderCellText(headerWidth, getText("report.config.option.defaultValue")); + sink.tableCell(cellWidth); + sink.nonBreakingSpace(); + sink.bold(); + sink.text(option.getDefaultValue()); + sink.bold_(); + sink.tableCell_(); + sink.tableRow_(); + + sink.tableRow(); + sinkHeaderCellText(headerWidth, getText("report.config.option.type")); + sink.tableCell(cellWidth); + sink.nonBreakingSpace(); + sink.text(option.getType().getName()); + sink.tableCell_(); + sink.tableRow_(); + + sink.tableRow(); + sinkHeaderCellText(headerWidth, getText("report.config.option.final")); + sink.tableCell(cellWidth); + sink.nonBreakingSpace(); + sink.text(getText(option.isFinal())); + sink.tableCell_(); + sink.tableRow_(); + + sink.tableRow(); + sinkHeaderCellText(headerWidth, getText("report.config.option.transient")); + sink.tableCell(cellWidth); + sink.nonBreakingSpace(); + sink.text(getText(option.isTransient())); + sink.tableCell_(); + sink.tableRow_(); + + sink.table_(); + + sink.paragraph(); + sink.link("./application-config-report.html#detail_options_" + configProvider.getName()); + sink.text(getText("report.back.options.table")); + sink.link_(); + sink.paragraph_(); + + sink.section4_(); + + } + + protected String getText(Boolean key) { + return i18n.getString(bundleName, locale, "report." + String.valueOf(key)); + } + + /** + * Gets the localized message for this report. + * + * @param key the message key. + * @return the message. + */ + protected String getText(String key) { + return i18n.getString(bundleName, locale, key); + } + + protected void renderWarningIcon() { + sink.figure(); + sink.figureGraphics("images/icon_warning_sml.gif"); + sink.figure_(); + } + + protected void renderErrorIcon() { + sink.figure(); + sink.figureGraphics("images/icon_error_sml.gif"); + sink.figure_(); + } + + protected void renderSuccessIcon() { + sink.figure(); + sink.figureGraphics("images/icon_success_sml.gif"); + sink.figure_(); + } + + protected void renderInfoIcon() { + sink.figure(); + sink.figureGraphics("images/icon_info_sml.gif"); + sink.figure_(); + } + + protected void sinkHeaderCellText(String text) { + sink.tableHeaderCell(); + sink.text(text); + sink.tableHeaderCell_(); + } + + protected void sinkHeaderCellText(String width, String text) { + sink.tableHeaderCell(width); + sink.text(text); + sink.tableHeaderCell_(); + } + + protected void sinkCellText(String width, String text) { + sink.tableCell(width); + sink.text(text); + sink.tableCell_(); + } + + protected void sinkCellText(String text) { + sink.tableCell(); + sink.text(text); + sink.tableCell_(); + } + + protected void sinkCellVerbatimText(String text) { + sink.tableCell(); + sink.verbatim(SinkEventAttributeSet.MONOSPACED); + sink.text(text); + sink.verbatim_(); + sink.tableCell_(); + } + + protected void sinkCellLink(String text, String url) { + sink.tableCell(); + sink.link(url); + sink.text(text); + sink.link_(); + sink.tableCell_(); + } + +} Property changes on: trunk/nuiton-util-maven-report-plugin/src/main/java/org/nuiton/util/plugin/report/ApplicationConfigReportRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report.properties =================================================================== --- trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report.properties (rev 0) +++ trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report.properties 2012-05-01 10:45:30 UTC (rev 2323) @@ -0,0 +1,53 @@ +### +# #%L +# Nuiton Utils :: Nuiton Maven Report Plugin +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 CodeLutin +# %% +# 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% +### +report.title=ApplicationConfig Report +report.description=Provides details of configuration options useable on the project. +report.overview.title=Overview +report.overview.text=This report summarizes all configuration options useable on the project. +report.detail.text.noConfig=No configuration found in class-path. +report.config.name=Name of configuration +report.config.description=Description +report.config.nbOptions=Number of options +report.config.nbActions=Number of actions +report.config.option.key=Key +report.config.option.description=Description +report.config.option.type=Type +report.config.option.defaultValue=Default Value +report.config.option.final=Can be modified +report.config.option.transient=Can be saved +report.config.option.detail=Details of option +report.true=Yes +report.false=No +report.back.options.table=Back to options table + +report.detail.title=Detail of configurations +report.detail.text=We give details of each configuration of the project +report.detail.configuration.title=Configuration +report.detail.options.title=Configuration options +report.detail.actions.title=Configuration actions +report.detail.options.noOptions=No option found for this configuration +report.detail.actions.noActions=No action found for this configuration + + Property changes on: trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_en.properties =================================================================== --- trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_en.properties (rev 0) +++ trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_en.properties 2012-05-01 10:45:30 UTC (rev 2323) @@ -0,0 +1,24 @@ +### +# #%L +# Nuiton Utils :: Nuiton Maven Report Plugin +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 CodeLutin +# %% +# 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% +### Property changes on: trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_en.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_fr.properties =================================================================== --- trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_fr.properties (rev 0) +++ trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_fr.properties 2012-05-01 10:45:30 UTC (rev 2323) @@ -0,0 +1,50 @@ +### +# #%L +# Nuiton Utils :: Nuiton Maven Report Plugin +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 CodeLutin +# %% +# 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% +### +report.title=Rapport ApplicationConfig +report.description=Fournit des informations sur les configurations utilisables dans le projet. +report.overview.title=Pr\u00E9ambule +report.overview.text=Ce rapport d\u00E9crit les configurations utilisables dans ce projet. +report.detail.text.noConfig=Aucune configuration trouv\u00E9e dans le class-path. +report.config.option.key=Clef +report.config.option.description=Description +report.config.option.type=Type +report.config.option.defaultValue=Valeur par d\u00E9faut +report.config.option.final=Option modifiable +report.config.option.transient=Option non sauvegardable +report.config.name=Nom de la configuration +report.config.description=Description +report.config.nbOptions=Nombre d'options +report.config.nbActions=Nombre d'actions +report.config.option.detail=D\u00E9tails de l'option +report.back.options.table=Retour sur la table des options +report.true=Oui +report.false=Non +report.detail.title=D\u00E9tail des configurations +report.detail.text=On d\u00E9taille ici une par une les configurations d\u00E9finies pour le projet +report.detail.configuration.title=Configuration +report.detail.options.title=Options de la configuration +report.detail.actions.title=Actions de la configuration +report.detail.options.noOptions=Aucune option d\u00E9finie pour cette configuration +report.detail.actions.noActions=Aucune action d\u00E9finie pour cette configuration \ No newline at end of file Property changes on: trunk/nuiton-util-maven-report-plugin/src/main/resources/application-config-report_fr.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigProvider.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigProvider.java (rev 0) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigProvider.java 2012-05-01 10:45:30 UTC (rev 2323) @@ -0,0 +1,79 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Utils + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 CodeLutin + * %% + * 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.util; + +import java.util.Locale; +import java.util.ServiceLoader; + +/** + * Provider of a {@link ApplicationConfig}. + * <p/> + * Each library of application which use {@link ApplicationConfig} should + * implements this and add the provider available via the + * {@link ServiceLoader} mecanism. + * <p/> + * Using such provider offers a nice way to find out what options can be loaded + * in a application. It also offers a simply way to generate application + * config report for documentation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.8 + */ +public interface ApplicationConfigProvider { + + /** + * Returns the name of the provided application config. + * <p/> + * This should be the name of the library or application which offers + * the configuration. + * + * @return the name of the provided application config + */ + String getName(); + + /** + * Returns the localized description of the configuration. + * + * @param locale locale used to render description + * @return the localized description of the configuration + */ + String getDescription(Locale locale); + + /** + * Returns all options offered by the configuration. + * + * @return all options offered by the configuration + * @see ApplicationConfig.OptionDef + */ + ApplicationConfig.OptionDef[] getOptions(); + + /** + * Returns all actions offered by the configuration. + * + * @return all actions offered by the configuration. + * @see ApplicationConfig.ActionDef + */ + ApplicationConfig.ActionDef[] getActions(); +} Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfigProvider.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native