Author: tchemit Date: 2009-01-22 04:10:02 +0000 (Thu, 22 Jan 2009) New Revision: 1312 Modified: commandline/ commandline/trunk/commandline-demo/pom.xml commandline/trunk/maven-commandline-plugin/changelog.txt commandline/trunk/maven-commandline-plugin/pom.xml commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/JavaGeneratorGoal.java commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/RstGeneratorContext.java commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/RstGeneratorGoal.java commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java Log: goals now tests is they have to generate something Property changes on: commandline ___________________________________________________________________ Name: svn:ignore + *.ipr *.iml Modified: commandline/trunk/commandline-demo/pom.xml =================================================================== --- commandline/trunk/commandline-demo/pom.xml 2009-01-21 16:26:29 UTC (rev 1311) +++ commandline/trunk/commandline-demo/pom.xml 2009-01-22 04:10:02 UTC (rev 1312) @@ -87,17 +87,16 @@ <configuration> <prefix>CommandLineDemo</prefix> <packageName>org.codelutin.commandline.demo</packageName> + <source>${maven.src.dir}/main/resources/commandline.properties</source> + <outClass>${basedir}/target/classes</outClass> </configuration> <executions> <execution> - <inherited>false</inherited> - <!-- do not use generate phase, since it will be reexecuted a second time... --> <id>genJava</id> <goals> <goal>genJava</goal> </goals> <configuration> - <source>${maven.src.dir}/main/resources/commandline.properties</source> <out>${maven.gen.dir}/java</out> <concreteConfig>true</concreteConfig> <concreteContextFQN>org.codelutin.commandline.demo.DemoContext</concreteContextFQN> @@ -116,8 +115,11 @@ <goal>genRst</goal> </goals> <configuration> + <bundles> + <bundle>fr_FR</bundle> + <bundle>en_GB</bundle> + </bundles> <rstFilePath>${maven.src.dir}/site/@bundle@/rst/user</rstFilePath> - <out>${basedir}/target/classes</out> <i18nCP>${maven.src.dir}/main/resources</i18nCP> </configuration> </execution> @@ -152,7 +154,7 @@ </dependencies> </plugin> - <plugin> + <plugin> <artifactId>maven-dependency-plugin</artifactId> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> Modified: commandline/trunk/maven-commandline-plugin/changelog.txt =================================================================== --- commandline/trunk/maven-commandline-plugin/changelog.txt 2009-01-21 16:26:29 UTC (rev 1311) +++ commandline/trunk/maven-commandline-plugin/changelog.txt 2009-01-22 04:10:02 UTC (rev 1312) @@ -1,3 +1,4 @@ 1.0 chemit 200901?? + * 20090122 [chemit] - goals now tests is they have to generate something * 20090121 [chemit] - refactor pom for sibling module dependencies * 20081205 [chemit] use lutinproject 3.2 Modified: commandline/trunk/maven-commandline-plugin/pom.xml =================================================================== --- commandline/trunk/maven-commandline-plugin/pom.xml 2009-01-21 16:26:29 UTC (rev 1311) +++ commandline/trunk/maven-commandline-plugin/pom.xml 2009-01-22 04:10:02 UTC (rev 1312) @@ -45,6 +45,13 @@ <scope>compile</scope> </dependency> + <dependency> + <groupId>org.codelutin</groupId> + <artifactId>lutinpluginutil</artifactId> + <version>0.2</version> + <scope>compile</scope> + </dependency> + </dependencies> <!-- ************************************************************* --> @@ -94,7 +101,7 @@ <plugin> <artifactId>maven-plugin-plugin</artifactId> </plugin> - + </plugins> </reports> <!-- ************************************************************* --> Modified: commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/JavaGeneratorGoal.java =================================================================== --- commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/JavaGeneratorGoal.java 2009-01-21 16:26:29 UTC (rev 1311) +++ commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/JavaGeneratorGoal.java 2009-01-22 04:10:02 UTC (rev 1312) @@ -32,6 +32,7 @@ import org.codelutin.option.generate.java.OptionParserJavaGenerator; import org.codelutin.option.generate.util.AbstractGeneratorGoal; import org.codelutin.util.FileUtil; +import org.codelutin.util.MirroredFileUpdater; import java.io.File; import java.io.IOException; @@ -51,36 +52,21 @@ /** * chemin du repertoire de generation des resources. * - * @parameter expression="${jaxx.outResource}" default-value="${basedir}/target/generated-sources/resources" + * @parameter expression="${commandline.outResource}" default-value="${basedir}/target/generated-sources/resources" */ protected File outResource; /** - * chemin du repertoire de compilation des resources. - * - * @parameter expression="${jaxx.outClass}" default-value="${basedir}/target/classes" - */ - protected File outClass; - - /** * flag to copy generated resource files to outClass * - * @parameter expression="${jaxx.copyToCP}" default-value="true" + * @parameter expression="${commandline.copyToCP}" default-value="true" */ protected boolean copyToCP; /** - * fichier de proprietes contenant les definitions d'options a utiliser. - * - * @parameter expression="${commandline.source}" - * @required - */ - protected File source; - - /** * Repertoire de sortie. * - * @parameter expression="${commandline.out}" default-value="${maven.src.dir}/java" + * @parameter expression="${commandline.out}" default-value="${maven.src.dir}/main/java" * @required */ protected File out; @@ -104,7 +90,7 @@ /** * flag to show errors of parsing. * - * @parameter expression="${commandLine.showError}" default-value="true" + * @parameter expression="${commandline.showError}" default-value="true" */ protected boolean showErrors; @@ -235,7 +221,7 @@ map.put(context.getKey(), optionClassName); } - boolean hasConfig = getContext().getConfigContexts().length>0; + boolean hasConfig = getContext().getConfigContexts().length > 0; // generate specialized abstract OptionAction for this parser if (needSpecializedAction()) { @@ -296,6 +282,18 @@ generateConcreteContextDeclaration(); } + @Override + protected boolean isUpToDate() { + MirroredFileUpdater updater = new MirroredFileUpdater(source.getParentFile(), outClass) { + @Override + public File getMirrorFile(File f) { + String file = f.getAbsolutePath().substring(prefixSourceDirecotory); + return new File(destinationDirectory + File.separator + file); + } + }; + return updater.isFileUpToDate(source); + } + public File getOut() { return out; } Modified: commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/RstGeneratorContext.java =================================================================== --- commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/RstGeneratorContext.java 2009-01-21 16:26:29 UTC (rev 1311) +++ commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/RstGeneratorContext.java 2009-01-22 04:10:02 UTC (rev 1312) @@ -110,12 +110,7 @@ } i++; } - //ClassLoader parent = Thread.currentThread().getContextClassLoader(); - if (compileClasspathElements.size() == 0) { - result = new URLClassLoader(url, getClass().getClassLoader()); - } else { - result = new URLClassLoader(url, getClass().getClassLoader()); - } + result = new URLClassLoader(url, getClass().getClassLoader()); } catch (MalformedURLException eee) { throw new RuntimeException(_("commandline.error.loader", getOut(), eee.getMessage()), eee); } catch (IOException e) { Modified: commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/RstGeneratorGoal.java =================================================================== --- commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/RstGeneratorGoal.java 2009-01-21 16:26:29 UTC (rev 1311) +++ commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/RstGeneratorGoal.java 2009-01-22 04:10:02 UTC (rev 1312) @@ -42,6 +42,7 @@ * @author chemit * @goal genRst * @phase process-classes + * @requiresDependencyResolution compile */ public class RstGeneratorGoal extends AbstractGeneratorGoal<RstGeneratorContext> { @@ -54,14 +55,6 @@ protected File i18nCP; /** - * Repertoire de sortie. - * - * @parameter expression="${commandline.out}" default-value="${basedir}/target/classes" - * @required - */ - protected File out; - - /** * Target rst file. * * @parameter expression="${commandline.rstFilePath}" @@ -73,6 +66,7 @@ * Target rst file. * * @parameter expression="${commandline.bundles}" + * @required */ protected String[] bundles; @@ -80,6 +74,23 @@ super(RstGeneratorContext.class); } + @Override + protected boolean isUpToDate() { + + for (String bundle : getBundles()) { + + String filename = getPrefix() + "Usage.rst"; + + Locale locale = I18n.newLocale(bundle); + + File rstFilePath = new File(this.rstFilePath.replace("@bundle@", locale.getLanguage()) + File.separator + filename); + if (rstFilePath.exists() && source.lastModified() > rstFilePath.lastModified()) { + return false; + } + } + return true; + } + public void generate() throws Exception { List<OptionKey> optionKeys = ReflectUtil.getConstants(getContext().getParserClass(), OptionKey.class); @@ -165,17 +176,13 @@ } public File getOut() { - return out; + return outClass; } public String[] getBundles() { return bundles; } - public void setOut(File out) { - this.out = out; - } - public void setBundles(String[] bundles) { this.bundles = bundles; } Modified: commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java =================================================================== --- commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java 2009-01-21 16:26:29 UTC (rev 1311) +++ commandline/trunk/maven-commandline-plugin/src/main/java/org/codelutin/option/generate/util/AbstractGeneratorGoal.java 2009-01-22 04:10:02 UTC (rev 1312) @@ -55,6 +55,22 @@ protected String packageName; /** + * chemin du repertoire de compilation des classes. + * + * @parameter expression="${jaxx.outClass}" default-value="${basedir}/target/classes" + * @required + */ + protected File outClass; + + /** + * fichier de proprietes contenant les definitions d'options a utiliser. + * + * @parameter expression="${commandline.source}" + * @required + */ + protected File source; + + /** * @description prefix i18n pour la génération des clefs . * @parameter expression="${commandline.i18nPrefix}" */ @@ -72,6 +88,12 @@ */ protected String encoding; + /** + * @description flag pour forcer la génération + * @parameter expression="${commandline.force}" default-value="false" + */ + protected boolean force; + /** timestamp */ protected final long timestamp; @@ -90,12 +112,24 @@ protected abstract void generate() throws Exception; + protected abstract boolean isUpToDate(); + @SuppressWarnings({"unchecked"}) public void execute() throws MojoExecutionException, MojoFailureException { - System.setProperty("org.apache.commons.logging.LogFactory", org.apache.commons.logging.impl.LogFactoryImpl.class.getName()); + if (source == null) { + throw new MojoFailureException("mojo requires property source not to be null"); + } + if (!source.exists()) { + throw new MojoFailureException("mojo requires property source to exist (" + source + ")"); + } + if (!force && isUpToDate()) { + getLog().info(getClass().getSimpleName() + " : files are up to date"); + return; + } + try { // force UTF-8 encoding ! encoding = I18n.UTF_8_ENCONDING; @@ -178,7 +212,7 @@ * @param dirGen le repertoire de generation des fichiers java */ public void fixCompileSourceRoots(File dirGen) { - if (project!=null && !project.getCompileSourceRoots().contains(dirGen.getPath())) { + if (project != null && !project.getCompileSourceRoots().contains(dirGen.getPath())) { project.addCompileSourceRoot(dirGen.getPath()); } }