Author: tchemit Date: 2009-12-23 09:58:07 +0100 (Wed, 23 Dec 2009) New Revision: 1699 Added: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java Log: improve help mojo (dettach it from the jaxx generate mojo) Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java =================================================================== --- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java 2009-12-23 08:49:38 UTC (rev 1698) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java 2009-12-23 08:58:07 UTC (rev 1699) @@ -20,18 +20,9 @@ import org.apache.maven.plugin.MojoFailureException; import org.nuiton.i18n.I18n; -import org.nuiton.plugin.VelocityTemplateGenerator; -import org.nuiton.util.SortedProperties; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Properties; +import java.io.*; +import java.util.*; /** * Abstract Mojo to generate help stuff. @@ -41,16 +32,7 @@ */ public abstract class AbstractGenerateHelpMojo extends AbstractJaxxMojo { - protected static final String AUTOREMOVE_LINE = "REMOVE THS LINE TO DISABLE AUTO-REGENERATE THE FILE"; /** - * The directory where to create or update help files. - * - * @parameter expression="${jaxx.outHelp}" default-value="${project.basedir}/src/main/help" - * @required - * @since 1.3 - */ - protected File outHelp; - /** * The locales to generate for help, separeted by comma. * <p/> * The first locale given is the default locale. @@ -61,14 +43,32 @@ */ protected String locales; /** - * The name of the helpset to generate. + * Where to generate helpIds files. * - * @parameter expression="${jaxx.helpsetName}" default-value="${project.artifactId}" + * @parameter expression="${jaxx.outputHelpIds}" default-value="target/generated-sources/jaxx" * @required * @since 1.3 */ - protected String helpsetName; + private File outputHelpIds; /** + * The store of helpIds generated by the goal {@link GenerateMojo} and then + * used by the goal {@link GenerateHelpMojo}. + * + * @parameter expression="${jaxx.helpIdsFilename}" default-value="helpIds.properties" + * @required + * @since 1.3 + */ + private String helpIdsFilename; + /** + * The store of cumulate helpIds generated by the goal {@link GenerateMojo} and then + * used by the goal {@link GenerateHelpMojo}. + * + * @parameter expression="${jaxx.mergeHelpIdsFilename}" default-value="helpIds-all.properties" + * @required + * @since 1.3 + */ + private String mergeHelpIdsFilename; + /** * Flag to generate the search index. * * @parameter expression="${jaxx.generateSearch}" default-value="true" @@ -77,28 +77,27 @@ */ protected boolean generateSearch; /** - * The help ids discovered in {@link #helpIdsStore} files. - */ - protected static Properties helpIds; - /** * Default locale (the first locale in {@link #localesToTreate}. */ - protected Locale defaultLocale; + private Locale defaultLocale; /** * Locales to treate */ - protected Locale[] localesToTreate; + private Locale[] localesToTreate; /** * Do the action for the given locale. * * @param locale the locale to treate * @param isDefaultLocale {@code true} if given locale is de the default locale - * @param localizedTarget where are stored help files for the given locale + * @param source where are stored help files for the given locale * @param localePath the locale path to use (is {@code default} if given locale is default). * @throws Exception if any pb */ - protected abstract void doActionForLocale(Locale locale, boolean isDefaultLocale, File localizedTarget, String localePath) throws Exception; + protected abstract void doActionForLocale(Locale locale, + boolean isDefaultLocale, + File source, + String localePath) throws Exception; /** * Call back after doing all stuff for all locales declared @@ -106,22 +105,15 @@ protected abstract void postDoAction(); @Override - public boolean init() throws Exception { + protected boolean init() throws Exception { - File idsStore = getHelpIdsStore(); - - if (!idsStore.exists()) { - getLog().info("no helpIdStore to react at " + idsStore); - return false; - } - if (locales == null || locales.trim().isEmpty()) { throw new MojoFailureException("You must set the 'locales' property properly (was " + locales + ")."); } // check there is a outHelp - if (outHelp == null) { - throw new MojoFailureException("You must set the 'outHelp' property."); + if (getTargetDirectory() == null) { + throw new MojoFailureException("You must set the 'outputHelpXXX' property."); } List<Locale> tmp = new ArrayList<Locale>(); @@ -139,32 +131,16 @@ createDirectoryIfNecessary(getTargetDirectory()); - // load ids from idsStore file (only once by session) - - if (helpIds == null) { - helpIds = new SortedProperties(); - - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(idsStore), getEncoding())); - String id; - while ((id = reader.readLine()) != null) { - id = id.trim(); - String path = id.replaceAll("\\.", File.separator) + ".html"; - helpIds.put(id, path); - } - - if (helpIds.isEmpty()) { - - // no ids detected - getLog().warn("No helpIds detected, will skip."); - return false; - } - } return true; } @Override - public final void doAction() throws Exception { + protected void doAction() throws Exception { + if (skipAction()) { + return; + } + for (Locale locale : localesToTreate) { boolean isDefaultLocale = locale == defaultLocale; @@ -173,39 +149,114 @@ String localePath = (isDefaultLocale ? "default" : language); - File localizedTarget = new File(outHelp, localePath); + File source = new File(getTargetDirectory(), localePath); - createDirectoryIfNecessary(localizedTarget); + createDirectoryIfNecessary(source); - doActionForLocale(locale, isDefaultLocale, localizedTarget, localePath); + doActionForLocale(locale, isDefaultLocale, source, localePath); } postDoAction(); } - @Override - public File getTargetDirectory() { - return outHelp; + protected boolean skipAction() { + if (!generateHelp) { + getLog().info("generateHelp flag is off, generate nothing."); + return true; + } + return false; } - @Override - public void setTargetDirectory(File targetDirectory) { - this.outHelp = targetDirectory; + public File getOutputHelpIds() { + return outputHelpIds; } - protected void doGen(File template, File f, Properties env) throws Exception { - VelocityTemplateGenerator gen = prepareGenerator(template); - gen.generate(env, f); + public void setOutputHelpIds(File outputHelpIds) { + this.outputHelpIds = outputHelpIds; } - protected VelocityTemplateGenerator prepareGenerator(File template) throws Exception { - URL templateURL = getTemplate(template); + public File getHelpIdsStoreFile() { + return outputHelpIds == null ? null : new File(outputHelpIds, helpIdsFilename); + } - if (verbose) { - getLog().info("using template " + templateURL); + public File getMergeHelpIdsStoreFile() { + return outputHelpIds == null ? null : new File(outputHelpIds, mergeHelpIdsFilename); + } + + public String getHelpIdsFilename() { + return helpIdsFilename; + } + + public void setHelpIdsFilename(String helpIdsFilename) { + this.helpIdsFilename = helpIdsFilename; + } + + public String getMergeHelpIdsFilename() { + return mergeHelpIdsFilename; + } + + public void setMergeHelpIdsFilename(String mergeHelpIdsFilename) { + this.mergeHelpIdsFilename = mergeHelpIdsFilename; + } + + protected void cleanHelpIdsStore() throws IOException { + File idsStore = getHelpIdsStoreFile(); + if (idsStore.exists()) { + if (getLog().isDebugEnabled()) { + getLog().debug("delete id store " + idsStore); + } + boolean b = idsStore.delete(); + if (!b) { + throw new IOException("could not delete file " + idsStore); + } } - VelocityTemplateGenerator gen = new VelocityTemplateGenerator(project, templateURL); - return gen; } + + protected Set<String> loadHelpIds(File file) throws IOException { + + BufferedReader reader = null; + Set<String> result = new HashSet<String>(); + try { + reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), getEncoding())); + String id; + while ((id = reader.readLine()) != null) { + result.add(id.trim()); + } + if (isVerbose()) { + getLog().info("load " + result.size() + " help ids from file " + file); + } + return result; + } finally { + if (reader != null) { + reader.close(); + } + } + } + + protected void storeHelpIds(File file, Set<String> ids) throws IOException { + + createDirectoryIfNecessary(file.getParentFile()); + + StringBuilder buffer = new StringBuilder(); + + for (String helpId : ids) { + buffer.append(removeQuote(helpId)).append('\n'); + } + writeFile(file, buffer.toString(), getEncoding()); + if (isVerbose()) { + getLog().info("stored " + ids.size() + " help ids in " + file); + } + } + + protected String removeQuote(String txt) { + if (txt.startsWith("\"")) { + txt = txt.substring(1); + } + if (txt.endsWith("\"")) { + txt = txt.substring(0, txt.length() - 1); + } + return txt; + } + } \ No newline at end of file Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java =================================================================== --- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2009-12-23 08:49:38 UTC (rev 1698) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2009-12-23 08:58:07 UTC (rev 1699) @@ -20,18 +20,17 @@ import org.apache.maven.model.Resource; import org.apache.maven.project.MavenProject; +import org.nuiton.plugin.AbstractPlugin; +import org.nuiton.util.FileUtil; import java.io.File; import java.io.IOException; import java.util.List; -import org.nuiton.plugin.AbstractPlugin; - /** - * Abract Jaxx Mojo. + * Abstract Jaxx Mojo. * * @author chemit - * * @since 1.3 */ public abstract class AbstractJaxxMojo extends AbstractPlugin { @@ -39,6 +38,7 @@ public abstract File getTargetDirectory(); public abstract void setTargetDirectory(File targetDirectory); + /** * Dépendance du projet. * @@ -46,32 +46,39 @@ * @required * @readonly */ - protected MavenProject project; + private MavenProject project; /** * Encoding pour la generation des fichiers * * @parameter expression="${jaxx.encoding}" default-value="${project.build.sourceEncoding}" * @since 2.0.0 */ - protected String encoding; + private String encoding; /** * verbose flag * * @parameter expression="${jaxx.verbose}" default-value="false" - * * @since 1.3 */ - protected boolean verbose; + private boolean verbose; + /** - * The store of helpIds generated by the goal {@link GenerateMojo} and then - * used by the goal {@link GenerateHelpMojo}. - * - * @parameter expression="${jaxx.helpIdsStore}" default-value="target/generated-sources/jaxx/helpIds.properties" - * @required + * to force generation of java source for any jaxx files with no timestamp checking. + * <p/> + * By default, never force generation. * + * @parameter expression="${jaxx.force}" default-value="false" + */ + private boolean force; + /** + * Flag to activate help id detection while parsing jaxx files. + * <p/> + * By default, not active. + * + * @parameter expression="${jaxx.generateHelp}" default-value="false" * @since 1.3 */ - protected File helpIdsStore; + protected boolean generateHelp; @Override protected boolean checkPackaging() { @@ -98,14 +105,6 @@ this.verbose = verbose; } - public File getHelpIdsStore() { - return helpIdsStore; - } - - public void setHelpIdsStore(File helpIdsStore) { - this.helpIdsStore = helpIdsStore; - } - public String getEncoding() { return encoding; } @@ -114,6 +113,14 @@ this.encoding = encoding; } + public boolean isForce() { + return force; + } + + public void setForce(boolean force) { + this.force = force; + } + /** * TODO-TC20091221 Should move this to AbstractPlugin * Create the directory if necessary. @@ -128,7 +135,7 @@ } boolean b = dir.mkdirs(); if (!b) { - throw new IOException("could not create directory "+dir); + throw new IOException("could not create directory " + dir); } } } @@ -177,4 +184,37 @@ } return shouldAdd; } + + + class GetLastModifiedFileAction implements FileUtil.FileAction { + + protected File lastFile; + + public GetLastModifiedFileAction(File lastFile) { + this.lastFile = lastFile; + + } + + @Override + public boolean doAction(File f) { + + if (f.lastModified() > lastFile.lastModified()) { + lastFile = f; + } + return true; + } + + public File getLastFile() { + return lastFile; + } + } + + protected Long getLastModified(File dir) { + if (!dir.exists()) { + return null; + } + GetLastModifiedFileAction fileAction = new GetLastModifiedFileAction(dir); + FileUtil.walkAfter(dir, fileAction); + return fileAction.getLastFile().lastModified(); + } } Copied: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java (from rev 1687, trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java) =================================================================== --- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java (rev 0) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java 2009-12-23 08:58:07 UTC (rev 1699) @@ -0,0 +1,519 @@ +/* *##% + * JAXX Maven plugin + * Copyright (C) 2008 - 2009 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>. + * ##%*/ +package org.nuiton.jaxx.plugin; + +import org.nuiton.plugin.VelocityTemplateGenerator; +import org.nuiton.util.FileUtil; +import org.nuiton.util.SortedProperties; + +import java.io.File; +import java.net.URL; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Properties; +import java.util.Set; + +/** + * Mojo to generate javax help files for your project. + * + * @author chemit + * @goal generate-help-files + * @phase process-sources + * @requiresProject + * @requiresDependencyResolution compile + * @execute goal=generate-help-ids + * @since 2.0.0 + */ +public class GenerateHelpFilesMojo extends AbstractGenerateHelpMojo { + + protected static final String AUTOREMOVE_LINE = "REMOVE THS LINE TO DISABLE AUTO-REGENERATE THE FILE"; + + /** + * The directory where to create or update help files. + * + * @parameter expression="${jaxx.outuptHelp}" default-value="${project.basedir}/src/main/help" + * @required + * @since 2.0.0 + */ + protected File outputHelp; + /** + * The name of the helpset to generate. + * + * @parameter expression="${jaxx.helpsetName}" default-value="${project.artifactId}" + * @required + * @since 1.3 + */ + protected String helpsetName; + /** + * The template used to generate helpset file. + * <p/> + * Must be an existing file or a ressource in class-path + * + * @parameter expression="${jaxx.helpsetTemplate}" default-value="/defaultHelpSet.hs.vm" + * @required + * @since 1.3 + */ + protected File helpsetTemplate; + /** + * The template used to generate helpset map file. + * <p/> + * Must be an existing file or a ressource in class-path + * + * @parameter expression="${jaxx.mapTemplate}" default-value="/defaultMap.jhm.vm" + * @required + * @since 1.3 + */ + protected File mapTemplate; + /** + * The template used to generate helpset index file. + * <p/> + * Must be an existing file or a ressource in class-path + * + * @parameter expression="${jaxx.indexTemplate}" default-value="/defaultIndex.xml.vm" + * @required + * @since 1.3 + */ + protected File indexTemplate; + /** + * The template used to generate helpset toc file. + * <p/> + * Must be an existing file or a ressource in class-path + * + * @parameter expression="${jaxx.tocTemplate}" default-value="/defaultToc.xml.vm" + * @required + * @since 1.3 + */ + protected File tocTemplate; + /** + * The template used to generate helpset content file. + * <p/> + * Must be an existing file or a ressource in class-path + * + * @parameter expression="${jaxx.contentTemplate}" default-value="/defaultContent.html.vm" + * @required + * @since 1.3 + */ + protected File contentTemplate; + + protected String mapFileName; + protected String indexFileName; + protected String tocFileName; + protected int touchedFiles; + + /** + * The help ids discovered. + */ + protected Properties helpIds; + + @Override + public File getTargetDirectory() { + return outputHelp; + } + + @Override + public void setTargetDirectory(File targetDirectory) { + this.outputHelp = targetDirectory; + } + + @Override + public boolean init() throws Exception { + if (!generateHelp) { + + return true; + } + // check ressources + checkResource(helpsetTemplate); + checkResource(mapTemplate); + checkResource(indexTemplate); + checkResource(tocTemplate); + checkResource(contentTemplate); + + mapFileName = helpsetName + "Map.jhm"; + indexFileName = helpsetName + "Index.xml"; + tocFileName = helpsetName + "TOC.xml"; + touchedFiles = 0; + + boolean b = super.init(); + if (!b) { + return false; + } + + // load ids from idsStore file + + File idsFile; + + if (isForce()) { + idsFile = getMergeHelpIdsStoreFile(); + if (!idsFile.exists()) { + if (isVerbose()) { + getLog().info("Force flag is on, but no helpIdStore-all to react at " + idsFile); + } + return true; + } + } else { + idsFile = getHelpIdsStoreFile(); + if (!idsFile.exists()) { + if (isVerbose()) { + getLog().info("no helpIdStore to react at " + idsFile); + } + return true; + } + } + + helpIds = new SortedProperties(); + + // loading all ids + Set<String> ids = loadHelpIds(idsFile); + + if (ids.isEmpty()) { + + // no ids detected + if (isVerbose()) { + getLog().info("No helpIds detected, will skip."); + } + return true; + } + + for (String id : ids) { + String path = id.replaceAll("\\.", File.separator) + ".html"; + helpIds.put(id, path); + } + + return true; + } + + @Override + protected boolean skipAction() { + boolean b = super.skipAction(); + if (!b) { + if (helpIds == null || helpIds.isEmpty()) { + getLog().info("No help ids to treate."); + return true; + } + } + return false; + } + +// @Override +// public void doAction() throws Exception { +// +// if (skipAction()) { +// return; +// } +// +// if (helpIds == null || helpIds.isEmpty()) { +// getLog().info("No help ids to treate."); +// return; +// } +// +// super.doAction(); +// } + + protected void postDoAction() { + getLog().info(touchedFiles + " file(s) treated."); + } + + protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File localizedTarget, String localePath) throws Exception { + + String language = locale.getLanguage(); + + getLog().info("Generate help for language " + language); + if (isVerbose()) { + getLog().info(" Localized target : " + localizedTarget); + } + + Properties env = new Properties(); + + env.put("helpSetName", helpsetName); + env.put("locale", language); + env.put("localePath", localePath); + env.put("separator", " "); + env.put("autoremoveLine", AUTOREMOVE_LINE); + + String localeSuffix = isDefaultLocale ? "" : "_" + language; + String helpsetFileName = helpsetName + localeSuffix + ".hs"; + + env.put("helpSetFileName", helpsetFileName); + + env.put("mapFileName", mapFileName); + env.put("indexFileName", indexFileName); + env.put("tocFileName", tocFileName); + env.put("generateSearch", generateSearch); + + // --------------------------------------------------------------- + // --- main helpset file ----------------------------------------- + // --------------------------------------------------------------- + + File file = new File(getTargetDirectory(), helpsetFileName); + + boolean doCreate = generateHelpsetFile(file, env); + + if (doCreate) { + touchedFiles++; + } + + // --------------------------------------------------------------- + // --- helpset map file ------------------------------------------ + // --------------------------------------------------------------- + + file = new File(localizedTarget, mapFileName); + + generateMapFile(file, env); + touchedFiles++; + + // --------------------------------------------------------------- + // --- helpset index file ---------------------------------------- + // --------------------------------------------------------------- + + file = new File(localizedTarget, indexFileName); + + generateIndexFile(file, env); + touchedFiles++; + + // --------------------------------------------------------------- + // --- helpset toc file ------------------------------------------ + // --------------------------------------------------------------- + + file = new File(localizedTarget, tocFileName); + + generateTocFile(file, env); + touchedFiles++; + + // --------------------------------------------------------------- + // --- helpset content files ------------------------------------- + // --------------------------------------------------------------- + + touchedFiles += generateContentFiles(localizedTarget, env, localePath); + } + + protected int generateContentFiles(File localizedTarget, Properties env, String localePath) throws Exception { + + int touchedFiles = 0; + VelocityTemplateGenerator gen = prepareGenerator(contentTemplate); + Enumeration<?> keys = helpIds.keys(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + String url = (String) helpIds.get(key); + url = helpsetName + File.separator + url; + File f = new File(localizedTarget, url); + boolean exist = f.exists(); + if (exist) { + // check if there is a autoremoveLine in content + String content = FileUtil.readAsString(f); + if (!content.contains(AUTOREMOVE_LINE)) { + // no regenerate marker detected, so skip this file + if (isVerbose()) { + getLog().debug("skip existing file " + f); + } + continue; + } + } + createDirectoryIfNecessary(f.getParentFile()); + if (isVerbose()) { + if (exist) { + getLog().info("regenerate content file " + f); + } else { + getLog().info("generate content file " + f); + } + } + env.put("helpId", key); + env.put("helpIdUrl", localePath + "/" + url); + gen.generate(env, f); + touchedFiles++; + } + return touchedFiles; + } + + protected boolean generateHelpsetFile(File file, Properties env) throws Exception { + + if (file.exists()) { + // check the autoremove line presence + String content = FileUtil.readAsString(file); + if (!content.contains(AUTOREMOVE_LINE)) { + // no regenerate marker detected, so skip this file + if (isVerbose()) { + getLog().info("skip existing helpset main file " + file); + } + return false; + } + } + + if (isVerbose()) { + if (file.exists()) { + getLog().info("regenerate helpset main file " + file); + } else { + getLog().info("generate helpset main file " + file); + } + } + doGen(helpsetTemplate, file, env); + return true; + } + + protected Properties generateMapFile(File file, Properties env) throws Exception { + + boolean create; + + Properties mergedHelpIds; + if (file.exists()) { + + // get back the exisiting data and merge it with incoming ones + + if (isVerbose()) { + getLog().info("loading existing helpset map file " + file); + } + + mergedHelpIds = XmlHelper.getExistingHelpIds(file, isVerbose(), getLog()); + create = false; + + } else { + + mergedHelpIds = new SortedProperties(); + create = true; + } + + // inject new helpIds + + for (Object k : helpIds.keySet()) { + mergedHelpIds.put(k, helpsetName + "/" + helpIds.get(k)); + } + + if (!mergedHelpIds.contains("top")) { + + // on ajoute une entree vers le root du helpset + + String topUrl = helpsetName + ".html"; + helpIds.put("top", topUrl); + mergedHelpIds.put("top", helpsetName + "/" + topUrl); + if (isVerbose()) { + getLog().debug("add top entry with url " + topUrl); + } + } + + if (isVerbose()) { + if (create) { + getLog().info("generate helpset map file " + file); + } else { + getLog().info("udpate helpset map file " + file); + } + } + + env.put("helpIds", mergedHelpIds); + doGen(mapTemplate, file, env); + env.remove("helpIds"); + return mergedHelpIds; + } + + protected NodeItem generateIndexFile(File file, Properties env) throws Exception { + NodeItem rootItem = null; + + boolean create; + + if (file.exists()) { + + create = false; + + rootItem = XmlHelper.getExistingItems("indexitem", file); + } else { + create = true; + } + + if (rootItem == null) { + rootItem = new NodeItem("top", helpsetName); + } + + // inject new index entries + + for (Object k : helpIds.keySet()) { + NodeItem toc = rootItem.findChild(k + ""); + if (isVerbose()) { + getLog().debug("index " + k + " : " + toc); + } + } + + if (isVerbose()) { + if (create) { + getLog().info("generate helpset index file " + file); + } else { + getLog().info("udpate helpset index file " + file); + } + } + + env.put("rootItem", rootItem); + doGen(indexTemplate, file, env); + env.remove("rootItem"); + return rootItem; + } + + protected NodeItem generateTocFile(File file, Properties env) throws Exception { + NodeItem rootItem = null; + + boolean create; + + if (file.exists()) { + + create = false; + + rootItem = XmlHelper.getExistingItems("tocitem", file); + } else { + create = true; + } + + if (rootItem == null) { + rootItem = new NodeItem("top", helpsetName); + } + // inject new toc entries + + for (Object k : helpIds.keySet()) { + NodeItem toc = rootItem.findChild(k + ""); + if (isVerbose()) { + getLog().debug("toc " + k + " : " + toc); + } + } + + if (isVerbose()) { + if (create) { + getLog().info("generate helpset toc file " + file); + } else { + getLog().info("udpate helpset toc file " + file); + } + } + + env.put("rootItem", rootItem); + doGen(tocTemplate, file, env); + env.remove("rootItem"); + return rootItem; + } + + + protected void doGen(File template, File f, Properties env) throws Exception { + VelocityTemplateGenerator gen = prepareGenerator(template); + gen.generate(env, f); + } + + protected VelocityTemplateGenerator prepareGenerator(File template) throws Exception { + URL templateURL = getTemplate(template); + + if (isVerbose()) { + getLog().info("using template " + templateURL); + } + VelocityTemplateGenerator gen = new VelocityTemplateGenerator(getProject(), templateURL); + return gen; + } + +} \ No newline at end of file Added: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java =================================================================== --- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java (rev 0) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java 2009-12-23 08:58:07 UTC (rev 1699) @@ -0,0 +1,110 @@ +package org.nuiton.jaxx.plugin; + +import jaxx.compiler.decorators.HelpRootCompiledObjectDecorator; +import org.apache.maven.plugin.MojoFailureException; + +import java.io.File; +import java.util.Locale; +import java.util.Set; + +/** + * Generate the help ids files from the previous jaxx generation. + * + * Created: 22 déc. 2009 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @author chemit + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + * @goal generate-help-ids + * @phase process-sources + * @requiresProject + * @since 2.0.0 + */ +public class GenerateHelpIdsMojo extends AbstractGenerateHelpMojo { + + @Override + public boolean init() throws Exception { + if (!generateHelp) { + + return true; + } + + if (!super.init()) { + return false; + } + + // check there is some bundle + if (getHelpIdsFilename() == null) { + throw new MojoFailureException("you must set the 'helpIdStore' property."); + } + if (getMergeHelpIdsFilename() == null) { + throw new MojoFailureException("you must set the 'helpIdStoreAll' property."); + } + + return true; + } + + @Override + public void doAction() throws Exception { + + if (skipAction()) { + return; + } + + Set<String> helpIds = HelpRootCompiledObjectDecorator.getHelpIds(); + + if (helpIds.isEmpty()) { +// if (isVerbose()) { + // no ids detected in this compilation round + getLog().info("No helpIds detected."); +// } + cleanHelpIdsStore(); + return; + } + + // store current jaxx session detected help ids + + File idsStore = getHelpIdsStoreFile(); + getLog().info("Store detected help ids to " + idsStore); + + storeHelpIds(idsStore, helpIds); + + // store merged help ids (to make possible a force on help generation) + + + File idsStoreAll = getMergeHelpIdsStoreFile(); + getLog().info("Merge help ids to " + idsStoreAll); + + if (idsStoreAll.exists()) { + Set<String> allIds = loadHelpIds(idsStoreAll); + helpIds.addAll(allIds); + allIds.clear(); + } + + storeHelpIds(idsStoreAll, helpIds); + + helpIds.clear(); + + } + + @Override + protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File source, String localePath) throws Exception { + } + + @Override + protected void postDoAction() { + } + + @Override + public File getTargetDirectory() { + return getOutputHelpIds(); + } + + @Override + public void setTargetDirectory(File targetDirectory) { + setOutputHelpIds(targetDirectory); + } +} Property changes on: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java =================================================================== --- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2009-12-23 08:49:38 UTC (rev 1698) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2009-12-23 08:58:07 UTC (rev 1699) @@ -18,376 +18,50 @@ * ##%*/ package org.nuiton.jaxx.plugin; -import org.nuiton.plugin.VelocityTemplateGenerator; -import org.nuiton.util.FileUtil; -import org.nuiton.util.SortedProperties; - import java.io.File; -import java.util.Enumeration; import java.util.Locale; -import java.util.Properties; /** - * Mojo to generate javax help stuff for your project. + * Mojo to generate all the javax help stuff for your project. * <p/> - * HelpIds should have been discovered by the JaxxMojo. + * This mojo will chain all others help mojo required. * * @author chemit * @goal generate-help * @phase process-sources * @requiresProject * @requiresDependencyResolution compile + * @execute goal=generate-help-search * @since 1.3 */ public class GenerateHelpMojo extends AbstractGenerateHelpMojo { - - /** - * The template used to generate helpset file. - * <p/> - * Must be an existing file or a ressource in class-path - * - * @parameter expression="${jaxx.helpsetTemplate}" default-value="/defaultHelpSet.hs.vm" - * @required - * @since 1.3 - */ - protected File helpsetTemplate; - /** - * The template used to generate helpset map file. - * <p/> - * Must be an existing file or a ressource in class-path - * - * @parameter expression="${jaxx.mapTemplate}" default-value="/defaultMap.jhm.vm" - * @required - * @since 1.3 - */ - protected File mapTemplate; - /** - * The template used to generate helpset index file. - * <p/> - * Must be an existing file or a ressource in class-path - * - * @parameter expression="${jaxx.indexTemplate}" default-value="/defaultIndex.xml.vm" - * @required - * @since 1.3 - */ - protected File indexTemplate; - /** - * The template used to generate helpset toc file. - * <p/> - * Must be an existing file or a ressource in class-path - * - * @parameter expression="${jaxx.tocTemplate}" default-value="/defaultToc.xml.vm" - * @required - * @since 1.3 - */ - protected File tocTemplate; - /** - * The template used to generate helpset content file. - * <p/> - * Must be an existing file or a ressource in class-path - * - * @parameter expression="${jaxx.contentTemplate}" default-value="/defaultContent.html.vm" - * @required - * @since 1.3 - */ - protected File contentTemplate; - - protected String mapFileName; - protected String indexFileName; - protected String tocFileName; - protected int touchedFiles; - @Override - public boolean init() throws Exception { - - // check ressources - checkResource(helpsetTemplate); - checkResource(mapTemplate); - checkResource(indexTemplate); - checkResource(tocTemplate); - checkResource(contentTemplate); - - mapFileName = helpsetName + "Map.jhm"; - indexFileName = helpsetName + "Index.xml"; - tocFileName = helpsetName + "TOC.xml"; - touchedFiles=0; - return super.init(); + public File getTargetDirectory() { + return null; } - protected void postDoAction() { - getLog().info(touchedFiles + " file(s) treated."); + @Override + public void setTargetDirectory(File targetDirectory) { } - protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File localizedTarget, String localePath) throws Exception { + @Override + public boolean init() throws Exception { - String language = locale.getLanguage(); - - getLog().info("Generate help for language " + language); - if (isVerbose()) { - getLog().info(" Localized target : " + localizedTarget); - } - - Properties env = new Properties(); - - env.put("helpSetName", helpsetName); - env.put("locale", language); - env.put("localePath", localePath); - env.put("separator", " "); - env.put("autoremoveLine", AUTOREMOVE_LINE); - - String localeSuffix = isDefaultLocale ? "" : "_" + language; - String helpsetFileName = helpsetName + localeSuffix + ".hs"; - - env.put("helpSetFileName", helpsetFileName); - - env.put("mapFileName", mapFileName); - env.put("indexFileName", indexFileName); - env.put("tocFileName", tocFileName); - env.put("generateSearch", generateSearch); - - // --------------------------------------------------------------- - // --- main helpset file ----------------------------------------- - // --------------------------------------------------------------- - - File file = new File(outHelp, helpsetFileName); - - boolean doCreate = generateHelpsetFile(file, env); - - if (doCreate) { - touchedFiles++; - } - - // --------------------------------------------------------------- - // --- helpset map file ------------------------------------------ - // --------------------------------------------------------------- - - file = new File(localizedTarget, mapFileName); - - generateMapFile(file, env); - touchedFiles++; - - // --------------------------------------------------------------- - // --- helpset index file ---------------------------------------- - // --------------------------------------------------------------- - - file = new File(localizedTarget, indexFileName); - - generateIndexFile(file, env); - touchedFiles++; - - // --------------------------------------------------------------- - // --- helpset toc file ------------------------------------------ - // --------------------------------------------------------------- - - file = new File(localizedTarget, tocFileName); - - generateTocFile(file, env); - touchedFiles++; - - // --------------------------------------------------------------- - // --- helpset content files ------------------------------------- - // --------------------------------------------------------------- - - touchedFiles += generateContentFiles(localizedTarget, env, localePath); - } - - protected int generateContentFiles(File localizedTarget, Properties env, String localePath) throws Exception { - - int touchedFiles = 0; - VelocityTemplateGenerator gen = prepareGenerator(contentTemplate); - Enumeration<?> keys = helpIds.keys(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - String url = (String) helpIds.get(key); - url = helpsetName + File.separator + url; - File f = new File(localizedTarget, url); - boolean exist = f.exists(); - if (exist) { - // check if there is a autoremoveLine in content - String content = FileUtil.readAsString(f); - if (!content.contains(AUTOREMOVE_LINE)) { - // no regenerate marker detected, so skip this file - if (verbose) { - getLog().debug("skip existing file " + f); - } - continue; - } - } - createDirectoryIfNecessary(f.getParentFile()); - if (verbose) { - if (exist) { - getLog().info("regenerate content file " + f); - } else { - getLog().info("generate content file " + f); - } - } - env.put("helpId", key); - env.put("helpIdUrl", localePath + "/" + url); - gen.generate(env, f); - touchedFiles++; - } - return touchedFiles; - } - - protected boolean generateHelpsetFile(File file, Properties env) throws Exception { - - if (file.exists()) { - // check the autoremove line presence - String content = FileUtil.readAsString(file); - if (!content.contains(AUTOREMOVE_LINE)) { - // no regenerate marker detected, so skip this file - if (verbose) { - getLog().info("skip existing helpset main file " + file); - } - return false; - } - } - - if (verbose) { - if (file.exists()) { - getLog().info("regenerate helpset main file " + file); - } else { - getLog().info("generate helpset main file " + file); - } - } - doGen(helpsetTemplate, file, env); return true; } - protected Properties generateMapFile(File file, Properties env) throws Exception { + @Override + public void doAction() throws Exception { - boolean create; - - Properties mergedHelpIds; - if (file.exists()) { - - // get back the exisiting data and merge it with incoming ones - - if (verbose) { - getLog().info("loading existing helpset map file " + file); - } - - mergedHelpIds = XmlHelper.getExistingHelpIds(file, verbose, getLog()); - create = false; - - } else { - - mergedHelpIds = new SortedProperties(); - create = true; - } - - // inject new helpIds - - for (Object k : helpIds.keySet()) { - mergedHelpIds.put(k, helpsetName + "/" + helpIds.get(k)); - } - - if (!mergedHelpIds.contains("top")) { - - // on ajoute une entree vers le root du helpset - - String topUrl = helpsetName + ".html"; - helpIds.put("top", topUrl); - mergedHelpIds.put("top", helpsetName + "/" + topUrl); - if (verbose) { - getLog().debug("add top entry with url " + topUrl); - } - } - - if (verbose) { - if (create) { - getLog().info("generate helpset map file " + file); - } else { - getLog().info("udpate helpset map file " + file); - } - } - - env.put("helpIds", mergedHelpIds); - doGen(mapTemplate, file, env); - env.remove("helpIds"); - return mergedHelpIds; } - protected NodeItem generateIndexFile(File file, Properties env) throws Exception { - NodeItem rootItem = null; - - boolean create; - - if (file.exists()) { - - create = false; - - rootItem = XmlHelper.getExistingItems("indexitem", file); - } else { - create = true; - } - - if (rootItem == null) { - rootItem = new NodeItem("top", helpsetName); - } - - // inject new index entries - - for (Object k : helpIds.keySet()) { - NodeItem toc = rootItem.findChild(k + ""); - if (verbose) { - getLog().debug("index " + k + " : " + toc); - } - } - - if (verbose) { - if (create) { - getLog().info("generate helpset index file " + file); - } else { - getLog().info("udpate helpset index file " + file); - } - } - - env.put("rootItem", rootItem); - doGen(indexTemplate, file, env); - env.remove("rootItem"); - return rootItem; + protected void postDoAction() { + //getLog().info(touchedFiles + " file(s) treated."); } - protected NodeItem generateTocFile(File file, Properties env) throws Exception { - NodeItem rootItem = null; + protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File localizedTarget, String localePath) throws Exception { - boolean create; - - if (file.exists()) { - - create = false; - - rootItem = XmlHelper.getExistingItems("tocitem", file); - } else { - create = true; - } - - if (rootItem == null) { - rootItem = new NodeItem("top", helpsetName); - } - // inject new toc entries - - for (Object k : helpIds.keySet()) { - NodeItem toc = rootItem.findChild(k + ""); - if (verbose) { - getLog().debug("toc " + k + " : " + toc); - } - } - - if (verbose) { - if (create) { - getLog().info("generate helpset toc file " + file); - } else { - getLog().info("udpate helpset toc file " + file); - } - } - - env.put("rootItem", rootItem); - doGen(tocTemplate, file, env); - env.remove("rootItem"); - return rootItem; } } Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java =================================================================== --- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java 2009-12-23 08:49:38 UTC (rev 1698) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java 2009-12-23 08:58:07 UTC (rev 1699) @@ -22,6 +22,7 @@ import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; +import org.nuiton.plugin.PluginHelper; import java.io.File; import java.io.PrintStream; @@ -31,7 +32,7 @@ import java.util.Locale; /** - * Mojo to generate javax search index help stuff for your project. + * Generate the javax search index help for your project. * <p/> * The current files should be generated always in a generated directory and not in * your src directories (this is mainly binary files not to be stored in scm system)... @@ -41,58 +42,136 @@ * @phase process-sources * @requiresProject * @requiresDependencyResolution compile + * @execute goal=generate-help-files * @since 2.0.0 */ public class GenerateHelpSearchMojo extends AbstractGenerateHelpMojo { - protected File targetRoot; + /** + * The directory where to create or update help search index files. + * + * @parameter expression="${jaxx.outputHelpSearch}" default-value="${project.basedir}/target/generated-sources/help" + * @required + * @since 2.0.0 + */ + protected File outputHelpSearch; + protected String timestamp; @Override public boolean init() throws Exception { + if (!generateHelp) { + + return true; + } + if (!generateSearch) { - getLog().info("Do not generate search."); - return false; +// getLog().info("Do not generate search."); + return true; } - targetRoot = getFileFromBasedir("target", "generated-sources", "help"); - createDirectoryIfNecessary(targetRoot); timestamp = "-" + System.currentTimeMillis(); return super.init(); } @Override - protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File localizedTarget, String localePath) throws Exception { + public File getTargetDirectory() { + return outputHelpSearch; + } + @Override + public void setTargetDirectory(File targetDirectory) { + this.outputHelpSearch = targetDirectory; + } + + protected boolean skipAction() { + if (!generateHelp) { + getLog().info("generateHelp flag is off, generate nothing."); + return true; + } + if (!generateSearch) { + getLog().info("generateHelpsearch flag is off, generate nothing."); + return true; + } + return false; + } + + @Override + protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File source, String localePath) throws Exception { + String language = locale.getLanguage(); - File target = new File(targetRoot, localePath + File.separator + "JavaHelpSearch"); + File target = new File(getTargetDirectory(), localePath + File.separator + "JavaHelpSearch"); - createDirectoryIfNecessary(localizedTarget); - createDirectoryIfNecessary(target); + // detect if need to generate + boolean generate = false; + + if (isForce()) { + + // always generate if force flag is no + generate = true; + + } else if (!target.exists()) { + + // target does not exist, must generate it + generate = true; + + } else { + + // see if there is something new in source + + Long sourceLast = getLastModified(source); + Long targetLast = getLastModified(target); + + if (isVerbose()) { + + getLog().info("lastModified of source : " + sourceLast); + getLog().info("lastModified of target : " + targetLast); + } + + if (targetLast == null || sourceLast == null || targetLast < sourceLast) { + + // something is newer in source than in target + + generate = true; + } + + } + + if (!generate) { + getLog().info("Nothing to generate for language " + language + " - all files are up to date."); + return; + } + getLog().info("Generate help search index for language " + language); + if (isVerbose()) { - getLog().info(" Localized source : " + localizedTarget); - getLog().info(" Localized target : " + target); + getLog().info(" from " + source); + getLog().info(" to " + target); } + createDirectoryIfNecessary(source); + createDirectoryIfNecessary(target); + // --------------------------------------------------------------- // --- generate search index ------------------------------------- // --------------------------------------------------------------- - generateSearchIndex(localizedTarget, target, locale); + generateSearchIndex(source, target, locale); } @Override protected void postDoAction() { // add resources to the project - addResourceDir(targetRoot, getProject(), "**/*"); + addResourceDir(getTargetDirectory(), getProject(), "**/*"); } protected void generateSearchIndex(File source, File target, Locale locale) throws Exception { + long t0 = System.nanoTime(); + Method m = Indexer.class.getDeclaredMethod("main", String[].class); // remove old index @@ -100,7 +179,9 @@ //copy resources to a tmp dir (without any VCS infos) File tmpDir = getFileFromBasedir("target", "jaxx-tmp", "indexer-" + locale + timestamp); - getLog().info("copy files to " + tmpDir + " for indexing them"); + if (isVerbose()) { + getLog().info("copy files to " + tmpDir + " for indexing them."); + } FileUtils.copyDirectory(source, tmpDir, "**/*", StringUtils.join(DirectoryScanner.DEFAULTEXCLUDES, ",")); // prepare arguments of Indexer.main calling @@ -122,7 +203,9 @@ System.setOut(out); System.setErr(err); } - getLog().info("Search Index generated for " + locale); + if (isVerbose()) { + getLog().info("Search Index generated for " + locale + " in " + PluginHelper.convertTime(System.nanoTime() - t0)); + } } } \ No newline at end of file Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java =================================================================== --- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2009-12-23 08:49:38 UTC (rev 1698) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2009-12-23 08:58:07 UTC (rev 1699) @@ -18,35 +18,28 @@ * ##%*/ package org.nuiton.jaxx.plugin; -import java.util.List; - +import jaxx.compiler.CompiledObjectDecorator; import jaxx.compiler.CompilerConfiguration; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.JAXXEngine; import jaxx.compiler.beans.BeanInfoUtil; -import jaxx.compiler.CompiledObjectDecorator; import jaxx.compiler.binding.DataBindingHelper; -import jaxx.compiler.decorators.HelpRootCompiledObjectDecorator; import jaxx.compiler.tags.TagManager; import jaxx.runtime.JAXXContext; - +import jaxx.runtime.swing.help.JAXXHelpBroker; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; - import org.nuiton.io.FileUpdaterHelper; import org.nuiton.io.MirroredFileUpdater; +import org.nuiton.plugin.PluginHelper; import java.io.File; -import java.io.IOException; -import java.util.Map; import java.util.Arrays; import java.util.HashMap; -import java.util.Set; +import java.util.List; +import java.util.Map; -import jaxx.runtime.swing.help.JAXXHelpBroker; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - /** * Generates some java code from jaxx files. * @@ -160,14 +153,6 @@ */ protected boolean addProjectClassPath; /** - * to force generation of java source for any jaxx files with no timestamp checking. - * <p/> - * By default, never force generation. - * - * @parameter expression="${jaxx.force}" default-value="false" - */ - protected boolean force; - /** * A flag to mark themojo to be used in a test phase. This will permits to add generated sources in test compile roots. * * @parameter expression="${jaxx.testPhase}" default-value="false" @@ -247,15 +232,6 @@ */ protected boolean showBinding; /** - * flag to activate help generation process. - * <p/> - * By default, not active. - * - * @parameter expression="${jaxx.generateHelp}" default-value="false" - * @since 1.3 - */ - protected boolean generateHelp; - /** * the FQN of help broker * <p/> * By default, use the JAXX implementation {@link JAXXHelpBroker}. @@ -315,13 +291,6 @@ @Override public boolean init() throws Exception { - if (generateHelp) { - // check there is some bundle - if (getHelpIdsStore() == null) { - throw new MojoFailureException("you must set the 'helpIdStore' property."); - } - } - fixCompileSourceRoots(); if (includes == null || includes.length == 0) { @@ -331,7 +300,7 @@ updater = FileUpdaterHelper.newJaxxFileUpdater(src, outJava); Map<File, String[]> result = new HashMap<File, String[]>(); - getFilesToTreateForRoots(includes, excludes, Arrays.asList(src.getAbsolutePath()), result, force ? null : updater); + getFilesToTreateForRoots(includes, excludes, Arrays.asList(src.getAbsolutePath()), result, isForce() ? null : updater); this.files = result.get(src); @@ -340,7 +309,7 @@ return true; } - cl = initClassLoader(project, + cl = initClassLoader(getProject(), src, addSourcesToClassPath, testPhase, @@ -377,13 +346,13 @@ for (String importS : imports) { imports[i++] = importS.trim(); } - if (verbose) { + if (isVerbose()) { getLog().info("extra imports " + java.util.Arrays.toString(imports)); } extraImports = imports; } - if (verbose) { + if (isVerbose()) { getLog().info(toString()); getLog().info("includes : " + Arrays.toString(includes)); for (String file : files) { @@ -394,10 +363,10 @@ } @Override - public void doAction() throws MojoExecutionException { + public void doAction() throws Exception { if (nofiles) { - getLog().info("No files to treate."); + getLog().info("Nothing to generate - all files are uo to date."); return; } @@ -407,9 +376,10 @@ DataBindingHelper.SHOW_LOG = showBinding; } try { + long t0 = System.nanoTime(); // force compiler init from here, not in a static block - TagManager.reset(verbose); + TagManager.reset(isVerbose()); engine = JAXXEngine.newLaunchor(src, files, this); int nbFiles = engine.run(); @@ -417,13 +387,8 @@ if (nbFiles == -1) { throw new MojoExecutionException("Aborting due to errors reported by jaxxc"); } - getLog().info("Generated " + nbFiles + " file(s). "); + getLog().info("Generated " + nbFiles + " file(s) in " + PluginHelper.convertTime(System.nanoTime() - t0)); - if (generateHelp) { - // generate help - generateHelp(); - } - } catch (MojoExecutionException e) { getLog().error(e); throw e; @@ -541,7 +506,9 @@ } protected void fixCompileSourceRoots() { - if (project == null) { + //FIXME TC20091222 : why this test ? should always have a project ? + // even in tests... + if (getProject() == null) { // no project defined, can not fix anything // this case could appear if we wanted to do some tests of the plugin return; @@ -554,41 +521,6 @@ } } - protected void generateHelp() throws IOException { - Set<String> helpIds = HelpRootCompiledObjectDecorator.getHelpIds(); - if (helpIds.isEmpty()) { - if (verbose) { - // no ids detected in this compilation round - getLog().info("no helpIds detected."); - } - return; - } - File idsStore = getHelpIdsStore(); - - createDirectoryIfNecessary(idsStore.getParentFile()); - - StringBuilder buffer = new StringBuilder(); - - for (String helpId : helpIds) { - buffer.append(removeQuote(helpId)).append('\n'); - } - writeFile(idsStore, buffer.toString(), encoding); - - getLog().info("helpIdStore generated in " + idsStore); - - helpIds.clear(); - } - - protected String removeQuote(String txt) { - if (txt.startsWith("\"")) { - txt = txt.substring(1); - } - if (txt.endsWith("\"")) { - txt = txt.substring(0, txt.length() - 1); - } - return txt; - } - protected void report(JAXXEngine engine) { List<String> warnings = engine.getWarnings(); if (!warnings.isEmpty()) {