Index: maven-commandline-plugin/src/java/org/codelutin/option/generate/AbstractGeneratorGoal.java diff -u maven-commandline-plugin/src/java/org/codelutin/option/generate/AbstractGeneratorGoal.java:1.9 maven-commandline-plugin/src/java/org/codelutin/option/generate/AbstractGeneratorGoal.java:1.10 --- maven-commandline-plugin/src/java/org/codelutin/option/generate/AbstractGeneratorGoal.java:1.9 Wed Feb 20 21:11:06 2008 +++ maven-commandline-plugin/src/java/org/codelutin/option/generate/AbstractGeneratorGoal.java Mon Mar 17 22:43:47 2008 @@ -20,22 +20,15 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; -import static org.codelutin.i18n.I18n._; +import org.codelutin.i18n.I18n; import org.codelutin.log.LutinLogFactory; import org.codelutin.util.StringUtil; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Set; - /** * Classe de base pour une goal de génération * @@ -43,9 +36,8 @@ */ public abstract class AbstractGeneratorGoal extends AbstractMojo { - static { - System.setProperty("org.apache.commons.logging.LogFactory", LutinLogFactory.class.getName()); - } + protected Log log = getLog(); + /** * @description Dépendance du projet. @@ -68,13 +60,6 @@ protected String i18nPrefix; /** - * @description classpath du projet qui utilise le plugin. - * @parameter expression="${commandline.cp}" default-value="${basedir}/target/classes" - * @required - */ - protected File cp; - - /** * @description flag pour afficher verbeusement ou non les logs * @parameter expression="${commandline.verbose}" default-value="${maven.verbose}" */ @@ -83,7 +68,7 @@ /** timestamp au démarrage (est positionné juste après l'init i18n) */ protected long t0; - protected ClassLoader loader; + //protected ClassLoader loader; protected AbstractGeneratorGoal() { } @@ -95,31 +80,19 @@ protected abstract void doAction() throws Exception; - protected abstract void initAction() throws Exception; + protected abstract void prepare() throws Exception; public void execute() throws MojoExecutionException, MojoFailureException { - t0 = System.nanoTime(); - if (i18nPrefix == null) { - i18nPrefix = prefix.toLowerCase(); - } - try { - Logger logger = Logger.getLogger("org.codelutin.option"); - if (verbose) { - // set logger to debug level - if (logger != null) { - logger.setLevel(Level.DEBUG); - } - } else { - if (logger != null) { - logger.setLevel(Level.INFO); - } - } - //initClassLoader(); - initAction(); + initGoal(); + + try { + // prepare arguments + prepare(); // do implented action doAction(); + } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } finally { @@ -127,40 +100,6 @@ } } - @SuppressWarnings({"unchecked"}) - protected ClassLoader initClassLoader() { - if (loader == null && project!=null) { - ClassLoader result; - try { - Set compileClasspathElements = project.getArtifacts(); - URL[] url = new URL[compileClasspathElements.size()]; - int i = 0; - for (Artifact artifact : compileClasspathElements) { - File file = new File(artifact.getFile().getAbsolutePath()); - if (file.getName().endsWith(".jar")) { - url[i] = new URL("jar", "", file.toURI().toURL().toString()+"!/"); - } else { - url[i] = file.toURI().toURL(); - } - //System.out.println("add url " + url[i]); - i++; - } - //ClassLoader parent = Thread.currentThread().getContextClassLoader(); - if (compileClasspathElements.size() == 0) { - result = new URLClassLoader(url, getClass().getClassLoader()); - } else { - result = new URLClassLoader(url); - } - } catch (MalformedURLException eee) { - throw new RuntimeException(_("Can't create ClassLoader for script, bad directory: {0} for reason {1}", cp, eee.getMessage()), eee); - } catch (IOException e) { - throw new RuntimeException(_("Can't create ClassLoader for script, bad directory: {0} for reason {1}", cp, e.getMessage()), e); - } - loader = result; - } - return loader; - } - protected void checkInstanceOf(String givenClass, Class expectedClass) { try { Class clazz = Class.forName(givenClass); @@ -172,4 +111,30 @@ throw new IllegalArgumentException(e); } } + + private void initGoal() { + + System.setProperty("org.apache.commons.logging.LogFactory", LutinLogFactory.class.getName()); + + t0 = System.nanoTime(); + + + if (i18nPrefix == null) { + i18nPrefix = prefix.toLowerCase(); + } + // init i18n + I18n.initISO88591(); + + Logger logger = Logger.getLogger("org.codelutin"); + if (verbose) { + // set logger to debug level + if (logger != null) { + logger.setLevel(Level.DEBUG); + } + } else { + if (logger != null) { + logger.setLevel(Level.INFO); + } + } + } } Index: maven-commandline-plugin/src/java/org/codelutin/option/generate/RstGeneratorGoal.java diff -u maven-commandline-plugin/src/java/org/codelutin/option/generate/RstGeneratorGoal.java:1.7 maven-commandline-plugin/src/java/org/codelutin/option/generate/RstGeneratorGoal.java:1.8 --- maven-commandline-plugin/src/java/org/codelutin/option/generate/RstGeneratorGoal.java:1.7 Fri Mar 14 23:39:22 2008 +++ maven-commandline-plugin/src/java/org/codelutin/option/generate/RstGeneratorGoal.java Mon Mar 17 22:43:47 2008 @@ -67,7 +67,7 @@ protected Class parserClass; @SuppressWarnings({"unchecked"}) - protected void initAction() throws ClassNotFoundException, MalformedURLException { + protected void prepare() throws ClassNotFoundException, MalformedURLException { getLog().info("projectCP:" + out); // add i18n location as classpath Resource.addDefaultClassLoader(new File(i18nCP).toURI().toURL()); Index: maven-commandline-plugin/src/java/org/codelutin/option/generate/JavaGeneratorGoal.java diff -u maven-commandline-plugin/src/java/org/codelutin/option/generate/JavaGeneratorGoal.java:1.14 maven-commandline-plugin/src/java/org/codelutin/option/generate/JavaGeneratorGoal.java:1.15 --- maven-commandline-plugin/src/java/org/codelutin/option/generate/JavaGeneratorGoal.java:1.14 Sun Mar 16 21:24:10 2008 +++ maven-commandline-plugin/src/java/org/codelutin/option/generate/JavaGeneratorGoal.java Mon Mar 17 22:43:47 2008 @@ -20,7 +20,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.plugin.MojoFailureException; -import org.codelutin.i18n.I18n; import static org.codelutin.i18n.I18n._; import org.codelutin.option.Option; import org.codelutin.option.OptionAction; @@ -182,10 +181,9 @@ super(prefix, verbose); } - protected void initAction() throws Exception { + protected void prepare() throws Exception { - // init i18n - I18n.initISO88591(); + //I18n.initISO88591(System.getProperty("user.language"), System.getProperty("user.country")); checkInstanceOf(parserSuperClass, OptionParser.class); @@ -241,7 +239,7 @@ // do parse definitions and return parser parser = DefinitionParser.doParse(typeP, source); - getLog().info(_("commandline.parser.result.info", parser, parser.getOptions().length, parser.getConfigs().length)); + log.info(_("commandline.parser.result.info", parser.getClass().getSimpleName(), parser.getOptions().length, parser.getConfigs().length)); //TODO Do same exception handling than the OptionPArser @@ -258,7 +256,7 @@ writer.close(); } else { - getLog().info(_("commandline.showErrors.no.error.info")); + log.info(_("commandline.showErrors.no.error.info")); } } @@ -334,14 +332,11 @@ // generate OptionParser implementation OptionParserJavaGenerator.doGenerate(out, t0, i18nPrefix, optionContexts, - configContexts, parserPackageName, parserSimpleName, optionKeySimpleName, optionPackageName, optionSimpleName, - configPackageName, - configSimpleName, actionPackageName, actionSimpleName, parserSuperClass