r2597 - trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin
Author: tchemit Date: 2013-03-08 00:16:14 +0100 (Fri, 08 Mar 2013) New Revision: 2597 Url: http://nuiton.org/projects/jaxx/repository/revisions/2597 Log: fixes #2566: Can merge helper ids into inpute files in generate-help-ids mojo + improve other helps mojos Modified: trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java Modified: trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java =================================================================== --- trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java 2013-03-07 17:30:11 UTC (rev 2596) +++ trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java 2013-03-07 23:16:14 UTC (rev 2597) @@ -119,6 +119,9 @@ /** Call back after doing all stuff for all locales declared */ protected abstract void postDoAction(); + /** Call back before doing all stuff for all locales declared */ + protected abstract void preDoAction() throws IOException; + @Override protected void init() throws Exception { @@ -163,6 +166,8 @@ @Override protected void doAction() throws Exception { + preDoAction(); + for (Locale locale : localesToTreate) { boolean isDefaultLocale = defaultLocale.equals(locale); @@ -231,7 +236,7 @@ protected Set<String> loadHelpIds(File file) throws IOException { - BufferedReader reader = null; + BufferedReader reader; Set<String> result = new HashSet<String>(); reader = new BufferedReader(new InputStreamReader( new FileInputStream(file), getEncoding())); Modified: trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java =================================================================== --- trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java 2013-03-07 17:30:11 UTC (rev 2596) +++ trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java 2013-03-07 23:16:14 UTC (rev 2597) @@ -35,6 +35,7 @@ import org.nuiton.util.SortedProperties; import java.io.File; +import java.io.IOException; import java.net.URL; import java.util.Enumeration; import java.util.Locale; @@ -213,6 +214,10 @@ } @Override + protected void preDoAction() throws IOException { + } + + @Override protected void postDoAction() { getLog().info(touchedFiles + " file(s) treated."); } Modified: trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java =================================================================== --- trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java 2013-03-07 17:30:11 UTC (rev 2596) +++ trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java 2013-03-07 23:16:14 UTC (rev 2597) @@ -24,12 +24,21 @@ */ package org.nuiton.jaxx.plugin; +import com.google.common.base.Charsets; +import com.google.common.io.Closeables; +import com.google.common.io.Files; import jaxx.compiler.decorators.HelpRootCompiledObjectDecorator; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.nuiton.util.SortedProperties; import java.io.File; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.HashSet; import java.util.Locale; import java.util.Set; @@ -45,6 +54,47 @@ defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = true) public class GenerateHelpIdsMojo extends AbstractGenerateHelpMojo { + public static final String INPUT_FILENAME_FORMAT = "%s_%s_%s.properties"; + + /** + * Flag to merge ids into input directory. + * + * @since 2.5.12 + */ + @Parameter(property = "jaxx.mergeIdsToInput", + defaultValue = "false", + required = true) + protected boolean mergeIdsToInput; + + /** + * Directory where to merge (create) input files. + * <p/> + * <strong>Note:</strong> Only used when {@code mergeIdsToInput} parameter + * is on. + * + * @since 2.5.12 + */ + @Parameter(property = "jaxx.inputHelpDirectory", + defaultValue = "src/main/resources/help", + required = true) + private File inputHelpDirectory; + + /** + * Prefix of input files. + * <p/> + * <strong>Note:</strong> {@code _locale.properties} will be added to each + * generated file. + * <p/> + * <strong>Note:</strong> Only used when {@code mergeIdsToInput} parameter + * is on. + * + * @since 2.5.12 + */ + @Parameter(property = "jaxx.inputHelpFilenamePrefix", + defaultValue = "helpMapping", + required = true) + private String inputHelpFilenamePrefix; + /** help ids to react. */ protected Set<String> helpIds; @@ -72,6 +122,10 @@ // always clean helpIdsStore before all cleanHelpIdsStore(); + if (mergeIdsToInput) { + createDirectoryIfNecessary(inputHelpDirectory); + } + } @Override @@ -91,8 +145,7 @@ } @Override - public void doAction() throws Exception { - + protected void preDoAction() throws IOException { // store current jaxx session detected help ids File idsStore = getHelpIdsStoreFile(); @@ -109,13 +162,9 @@ if (idsStoreAll.exists()) { Set<String> allIds = loadHelpIds(idsStoreAll); helpIds.addAll(allIds); - allIds.clear(); } storeHelpIds(idsStoreAll, helpIds); - - helpIds.clear(); - } @Override @@ -124,10 +173,60 @@ File source, String localePath) throws Exception { // nothing to do specific to locale + + if (mergeIdsToInput) { + + String filename = String.format( + INPUT_FILENAME_FORMAT, + inputHelpFilenamePrefix, + locale.getLanguage(), + locale.getCountry()); + + File inputFile = new File(inputHelpDirectory, filename); + + getLog().info("Use input file: " + inputFile); + + SortedProperties p = new SortedProperties(); + + if (inputFile.exists()) { + Reader reader = Files.newReader(inputFile, Charsets.UTF_8); + try { + p.load(reader); + reader.close(); + } finally { + Closeables.closeQuietly(reader); + } + } + Set<String> existingId = p.stringPropertyNames(); + Set<String> newIds = new HashSet<String>(); + for (String helpId : helpIds) { + newIds.add(removeQuote(helpId)); + } + newIds.removeAll(existingId); + if (!newIds.isEmpty()) { + + getLog().info("Add " + newIds.size() + " keys."); + + for (String helpId : newIds) { + p.put(helpId, ""); + } + + Writer writer = Files.newWriter(inputFile, Charsets.UTF_8); + try { + p.store(writer, "Generated by " + getClass().getName()); + writer.close(); + } finally { + Closeables.closeQuietly(writer); + } + + } + + } } @Override protected void postDoAction() { + helpIds.clear(); } @Override Modified: trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java =================================================================== --- trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2013-03-07 17:30:11 UTC (rev 2596) +++ trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2013-03-07 23:16:14 UTC (rev 2597) @@ -31,6 +31,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import java.io.File; +import java.io.IOException; import java.util.Locale; /** @@ -59,7 +60,10 @@ @Override public void doAction() throws Exception { + } + @Override + protected void preDoAction() throws IOException { } @Override Modified: trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java =================================================================== --- trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java 2013-03-07 17:30:11 UTC (rev 2596) +++ trunk/jaxx-maven-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java 2013-03-07 23:16:14 UTC (rev 2597) @@ -35,6 +35,7 @@ import org.nuiton.plugin.PluginHelper; import java.io.File; +import java.io.IOException; import java.io.PrintStream; import java.lang.reflect.Method; import java.util.ArrayList; @@ -127,7 +128,7 @@ if (isForce()) { - // always generate if force flag is no + // always generate if force flag is on generate = true; } else if (!target.exists()) { @@ -183,6 +184,10 @@ } @Override + protected void preDoAction() throws IOException { + } + + @Override protected void postDoAction() { // add resources to the project
participants (1)
-
tchemit@users.nuiton.org