Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java:1.14 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java:1.15 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java:1.14 Sun Mar 16 21:19:30 2008 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nPlugin.java Tue Mar 18 00:23:36 2008 @@ -148,12 +148,12 @@ protected String getLogEntry(String msg, int nbFiles, long time, long all) { long now = System.nanoTime(); long delta = now - time; - String s = getClass().getSimpleName() + " : " + msg; + String s = "["+artifactId+"] i18n."+getClass().getSimpleName() + " : " + msg; if (time > 0) { s += " (" + StringUtil.convertTime(delta) + ")"; } if (all > 0 && nbFiles > -1) { - s += "(total time:" + StringUtil.convertTime(now - all) + ") ( ~ " + StringUtil.convertTime(((now - all) / (nbFiles + 1))) + " /file)"; + s += "(total time:" + StringUtil.convertTime(now - all) + ") ( ~ " + StringUtil.convertTime(((now - all) / (nbFiles + 1))) + " / file)"; } return s; } Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java:1.3 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java:1.4 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java:1.3 Wed Jan 23 09:41:17 2008 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java Tue Mar 18 00:23:36 2008 @@ -18,10 +18,15 @@ * \#\#% */ package org.codelutin.i18n.plugin.core; +import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.util.DirectoryScanner; import java.io.File; +import java.lang.annotation.Annotation; +import java.net.URLClassLoader; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; /** * A simple model for a sourceEntry represents by a basedir and includes and/or exlucdes pattern. @@ -46,7 +51,7 @@ * If let to null, all goals can use this entry. */ protected String specificGoal = null; - + protected File basedir; protected String[] includes; @@ -86,9 +91,9 @@ } public boolean useForGoal(String goal) { - return specificGoal==null || specificGoal.equalsIgnoreCase(goal); + return specificGoal == null || specificGoal.equalsIgnoreCase(goal); } - + public boolean hasSrc() { return basedir != null; } @@ -134,4 +139,77 @@ } return sb.toString(); } + + public String[] getIncludedFiles(File basedir, String[] defaultIncludes, URLClassLoader loader, List annotationClass, Log log) { + List result = new ArrayList(); + + for (String s : getIncludedFiles(basedir, defaultIncludes)) { + if (filterByAnnotation(s, loader, annotationClass, log)) { + result.add(s); + } + } + return result.toArray(new String[result.size()]); + } + + protected boolean filterByAnnotation(String file, URLClassLoader loader, List annotationClass, Log log) { + + + Annotation annotation = getAnnotation(file, loader, annotationClass, log); + + boolean result = annotation != null; + + if (result && log.isDebugEnabled()) { + log.debug("find i18n annotated file : " + file); + } + return result; + } + + protected String getFQN(String file) { + String filePath = file; + filePath = filePath.substring(0, filePath.length() - ".java".length()); + String replaceEx = File.separator.equals("\\") ? "\\\\" : File.separator; + return filePath.replaceAll(replaceEx, "."); + } + + public Class getClass(String file, URLClassLoader loader, Log log) { + String fqn = getFQN(file); + try { + return loader.loadClass(fqn); + + } catch (Throwable e) { + log.warn("could not find class " + fqn + " " + e); + return null; + } + } + + public Annotation getAnnotation(String file, URLClassLoader loader, List annotationClass, Log log) { + + Class currentClass = getClass(file, loader, log); + + try { + Annotation[] annos = currentClass.getAnnotations(); + if (annos != null && annos.length > 0) { + for (Annotation anno : annos) { + if (annotationClass.contains(anno.annotationType().getName())) { + return anno; + } + } + } + } catch (Throwable e) { + log.warn("could not find annotation for " + file + " " + e); + } + return null; + + } + + public Class getClass(File file, URLClassLoader loader, Log log) { + String f = file.getAbsolutePath().substring(basedir.getAbsolutePath().length() + 1); + return getClass(f, loader, log); + } + + public Annotation getAnnotation(File file, URLClassLoader loader, List annotationClass, Log log) { + String f = file.getAbsolutePath().substring(basedir.getAbsolutePath().length() + 1); + return getAnnotation(f, loader, annotationClass, log); + } + } Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java:1.5 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java:1.6 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java:1.5 Wed Feb 20 20:31:41 2008 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/AbstractI18nParser.java Tue Mar 18 00:23:36 2008 @@ -25,10 +25,10 @@ import java.io.File; import java.io.FileInputStream; -import java.util.Properties; -import java.util.List; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +import java.util.Properties; /** * Abstract implementation for parsing goal. @@ -36,7 +36,6 @@ * @author tony */ public abstract class AbstractI18nParser extends AbstractI18nPlugin implements Parser { - /** @return the outGetter to use for the instance (java.getter,...) */ protected abstract String getOutGetter(); @@ -57,7 +56,7 @@ * @parameter expression="${i18n.treateDefault}" default-value="true" */ protected boolean treateDefaultEntry; - + /** * @description Source entries (src+includes+excludes) . * @parameter expression="${i18n.entries}" @@ -65,12 +64,18 @@ protected SourceEntry[] entries; protected Properties result; + protected Properties oldParser; - protected Properties oldLanguage; + protected Properties oldLanguage; protected int fileTreated = 0; protected long t0; + protected boolean touchFile; + protected List treadedFiles; + + protected SourceEntry currentEntry; + public void init() { t0 = System.nanoTime(); result = new Properties(); @@ -81,6 +86,7 @@ if (keysModifier) { addParserEvent(KeysModifier.getInstance(getKeyModifierStart(), getKeyModifierEnd())); } + treadedFiles = new ArrayList(); } /* @@ -97,13 +103,14 @@ try { // Reprise sur un ancien parsing File oldParserFile = new File(out.getAbsolutePath() + File.separatorChar + getOutGetter()); + File saveFile = new File(out.getAbsolutePath() + File.separatorChar + getOutGetter() + "~"); + if (!oldParserFile.exists()) { oldParserFile.getParentFile().mkdirs(); } oldParserFile.createNewFile(); oldParser.load(new FileInputStream(oldParserFile)); - File saveFile = new File(out.getAbsolutePath() + File.separatorChar + getOutGetter() + "~"); FileUtil.copy(oldParserFile, saveFile); // Anciennes clés disponnibles @@ -120,12 +127,14 @@ // Suppression du fichier sauvegarder saveFile.delete(); + int i = treadedFiles.size(); + getLog().info(getLogEntry(" success [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0)); + } catch (Exception e) { getLog().error("Error code parsing ", e); throw new MojoFailureException("Error code parsing"); } - getLog().info(getLogEntry(" success [treated file(s) : " + fileTreated + "]", fileTreated-1, 0, t0)); } public void parse() { @@ -136,15 +145,19 @@ for (SourceEntry entry : entries) { if (!entry.useForGoal(getClass().getSimpleName())) { if (verbose) { - getLog().debug("skip entry "+entry.toString()); + getLog().debug("skip entry " + entry.toString()); } continue; - } + } + currentEntry = entry; // get found files - String[] foundFiles = entry.getIncludedFiles(getDefaultBasedir(), getDefaultIncludes()); + String[] foundFiles = getFilesForEntry(entry); long t000 = System.nanoTime(); - - getLog().info(getLogEntry(" parse <" + entry + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0)); + if (verbose) { + getLog().debug(getLogEntry(" parse <" + entry + "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0)); + } else { + getLog().info(getLogEntry(" parse <" + entry .getBasedir()+ "> [incoming file(s) : " + foundFiles.length + "]", 0, 0, 0)); + } // launch parser for found files parseEntry(entry.getBasedir(), foundFiles); fileTreated += foundFiles.length; @@ -155,10 +168,14 @@ } } + protected String[] getFilesForEntry(SourceEntry entry) { + return entry.getIncludedFiles(getDefaultBasedir(), getDefaultIncludes()); + } + protected void addDefaultEntry() { List list; - if (entries==null|| entries.length==0) { + if (entries == null || entries.length == 0) { list = new ArrayList(); } else { list = new ArrayList(Arrays.asList(entries)); @@ -177,9 +194,13 @@ for (ParserEvent event : events) { event.eventChangeFile(file); } + touchFile = false; parseFile(file); - if (verbose) { - getLog().debug(getLogEntry(fileName, i, t000, t00)); + if (touchFile) { + treadedFiles.add(file); + if (verbose) { + getLog().debug(getLogEntry(fileName, i, t000, t00)); + } } for (ParserEvent event : events) { event.eventNextFile(file);