Index: maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorContext.java diff -u maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorContext.java:1.1 maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorContext.java:1.2 --- maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorContext.java:1.1 Wed Mar 19 20:21:42 2008 +++ maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorContext.java Thu Mar 20 01:30:55 2008 @@ -16,112 +16,69 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; import org.codelutin.option.generate.java.AbstractJavaGenerator; import java.io.File; +import java.io.IOException; /** * Main generator context with all needed data * * @author chemit */ -public abstract class AbstractGeneratorContext { +public abstract class AbstractGeneratorContext { - /** - * @description Dépendance du projet. - * @parameter expression="${commandline.prefix}" - * @required - */ - protected String prefix; - - /** - * @description Package where to generate. - * @parameter expression="${commandline.package}" - * @required - */ - protected String packageName; - - /** - * @description Répertoire de sortie. - * @parameter expression="${commandline.out}" - * @required - */ - protected File out; - - /** - * @description prefix i18n pour la génération des clefs . - * @parameter expression="${commandline.i18nPrefix}" - */ - protected String i18nPrefix; - - /** - * @description flag pour afficher verbeusement ou non les logs - * @parameter expression="${commandline.verbose}" default-value="${maven.verbose}" - */ - protected boolean verbose; - - /** - * @description encoding pour les fichiers a generer - * @parameter expression="${commandline.encoding}" default-value="${maven.compile.encoding}" - */ - protected String encoding; + protected G goal; public String getPrefix() { - return prefix; + return goal.getPrefix(); } - public void setPrefix(String prefix) { - this.prefix = prefix; + public MavenProject getProject() { + return goal.getProject(); } - public String getI18nPrefix() { - return i18nPrefix; - } - - public void setI18nPrefix(String i18nPrefix) { - this.i18nPrefix = i18nPrefix; + public long getTimestamp() { + return goal.getTimestamp(); } public boolean isVerbose() { - return verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; + return goal.isVerbose(); } public String getEncoding() { - return encoding; + return goal.getEncoding(); } - public void setEncoding(String encoding) { - this.encoding = encoding; + public String getI18nPrefix() { + return goal.getI18nPrefix(); } - public File getOut() { - return out; + public Log getLog() { + return goal.getLog(); } - public void setOut(File out) { - this.out = out; + public File getOut() { + return goal.getOut(); } public String getPackageName() { - return packageName; + return goal.getPackageName(); } - public void setPackageName(String packageName) { - this.packageName = packageName; - } + @SuppressWarnings({"unchecked"}) + public void init(G goal) throws IOException, ClassNotFoundException { - public void init() { + this.goal = (G) goal; - if (i18nPrefix == null) { - i18nPrefix = prefix.toLowerCase(); + if (getI18nPrefix() == null) { + goal.setI18nPrefix(getPrefix().toLowerCase()); } Logger logger = Logger.getLogger("org.codelutin"); - if (verbose) { + if (isVerbose()) { // set logger to debug level if (logger != null) { logger.setLevel(Level.DEBUG); @@ -131,14 +88,18 @@ logger.setLevel(Level.INFO); } } - if (encoding != null) { + if (getEncoding() != null) { // set encoding once for all - AbstractJavaGenerator.encoding = encoding; + AbstractJavaGenerator.encoding = getEncoding(); } // make sure out exists - if (!out.exists()) { - out.mkdirs(); + if (!getOut().exists()) { + getOut().mkdirs(); } } + + public G getGoal() { + return goal; + } } Index: maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java diff -u maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java:1.1 maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java:1.2 --- maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java:1.1 Wed Mar 19 20:21:42 2008 +++ maven-commandline-plugin/src/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java Thu Mar 20 01:30:55 2008 @@ -21,12 +21,12 @@ 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 org.codelutin.i18n.I18n; import org.codelutin.log.LutinLogFactory; import org.codelutin.util.StringUtil; +import java.io.File; + /** * Classe de base pour une goal de génération * @@ -34,8 +34,6 @@ */ public abstract class AbstractGeneratorGoal extends AbstractMojo { - protected Log log = getLog(); - /** * @description Dépendance du projet. * @parameter default-value="${project}" @@ -43,29 +41,64 @@ */ protected MavenProject project; - /** le contexte du generateur */ - protected C context; + /** + * @description prefix + * @parameter expression="${commandline.prefix}" + * @required + */ + protected String prefix; + + /** + * @description Package where to generate. + * @parameter expression="${commandline.packageName}" + * @required + */ + protected String packageName; + + /** + * @description prefix i18n pour la génération des clefs . + * @parameter expression="${commandline.i18nPrefix}" + */ + protected String i18nPrefix; + + /** + * @description flag pour afficher verbeusement ou non les logs + * @parameter expression="${commandline.verbose}" default-value="${maven.verbose}" + */ + protected boolean verbose; + + /** + * @description encoding pour les fichiers a generer + * @parameter expression="${commandline.encoding}" default-value="${maven.compile.encoding}" + */ + protected String encoding; /** timestamp */ protected final long timestamp; - protected AbstractGeneratorGoal(Class contextClass) { + private C context; + + protected AbstractGeneratorGoal(Class klass) { timestamp = System.nanoTime(); try { - context = contextClass.newInstance(); - } catch (Exception e) { + context = klass.newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { throw new RuntimeException(e); } } protected abstract void generate() throws Exception; + @SuppressWarnings({"unchecked"}) public void execute() throws MojoExecutionException, MojoFailureException { + System.setProperty("org.apache.commons.logging.LogFactory", LutinLogFactory.class.getName()); try { - // init generator - init(); + // init context + context.init(this); // do implented action generate(); @@ -77,30 +110,62 @@ } } - protected void init() throws Exception { + public C getContext() { + return context; + } - System.setProperty("org.apache.commons.logging.LogFactory", LutinLogFactory.class.getName()); + public String getPrefix() { + return prefix; + } - // init i18n - I18n.initISO88591(); + public String getEncoding() { + return encoding; + } - // init context - getContext().init(); + public String getI18nPrefix() { + return i18nPrefix; } - public C getContext() { - return context; + public abstract File getOut(); + + public String getPackageName() { + return packageName; } - protected void checkInstanceOf(String givenClass, Class expectedClass) { - try { - Class clazz = Class.forName(givenClass); - //Class clazz = Class.forName(givenClass, true, loader); - if (!expectedClass.isAssignableFrom(clazz)) { - throw new IllegalArgumentException("required a " + expectedClass + " class but found a " + clazz); - } - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException(e); - } + public MavenProject getProject() { + return project; + } + + public long getTimestamp() { + return timestamp; + } + + public boolean isVerbose() { + return verbose; + } + + public void setI18nPrefix(String i18nPrefix) { + this.i18nPrefix = i18nPrefix; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public void setProject(MavenProject project) { + this.project = project; } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + }