r1826 - in trunk/maven-jaxx-plugin: . src/main/java/org/nuiton/jaxx/plugin src/test/java/org/nuiton/jaxx/plugin src/test/resources
Author: tchemit Date: 2010-03-31 20:57:47 +0200 (Wed, 31 Mar 2010) New Revision: 1826 Log: Evolution #435: Regenerates jaxx files when his css file is modified + reformat + set to verbose mojo when debug log is on Modified: trunk/maven-jaxx-plugin/pom.xml trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerTest.java trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java trunk/maven-jaxx-plugin/src/test/resources/log4j.properties Modified: trunk/maven-jaxx-plugin/pom.xml =================================================================== --- trunk/maven-jaxx-plugin/pom.xml 2010-03-31 13:20:30 UTC (rev 1825) +++ trunk/maven-jaxx-plugin/pom.xml 2010-03-31 18:57:47 UTC (rev 1826) @@ -98,6 +98,13 @@ <classifier>tests</classifier> </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> <!-- ************************************************************* --> 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 2010-03-31 13:20:30 UTC (rev 1825) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2010-03-31 18:57:47 UTC (rev 1826) @@ -19,6 +19,7 @@ package org.nuiton.jaxx.plugin; import org.apache.maven.project.MavenProject; +import org.nuiton.io.MirroredFileUpdater; import org.nuiton.plugin.AbstractPlugin; import org.nuiton.util.FileUtil; @@ -150,4 +151,26 @@ FileUtil.walkAfter(dir, fileAction); return fileAction.getLastFile().lastModified(); } + + /** + * To test if a jaxx source (or his css ) file is newser than his generated + * java source file. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0.2 + */ + public static class JaxxFileUpdater extends MirroredFileUpdater { + + protected JaxxFileUpdater(File sourceDirectory, File destinationDirectory) { + super(".jaxx|*.css", ".java", sourceDirectory, destinationDirectory); + } + + @Override + public File getMirrorFile(File f) { + String file = f.getAbsolutePath().substring(prefixSourceDirecotory); + String extension = FileUtil.extension(f); + String mirrorRelativePath = file.substring(0, file.length() - extension.length()) + "java"; + return new File(destinationDirectory + File.separator + mirrorRelativePath); + } + } } 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 2010-03-31 13:20:30 UTC (rev 1825) +++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2010-03-31 18:57:47 UTC (rev 1826) @@ -18,11 +18,7 @@ * ##%*/ package org.nuiton.jaxx.plugin; -import jaxx.compiler.CompiledObjectDecorator; -import jaxx.compiler.CompilerConfiguration; -import jaxx.compiler.I18nHelper; -import jaxx.compiler.JAXXCompiler; -import jaxx.compiler.JAXXEngine; +import jaxx.compiler.*; import jaxx.compiler.beans.BeanInfoUtil; import jaxx.compiler.binding.DataBindingHelper; import jaxx.compiler.spi.DefaultInitializer; @@ -34,17 +30,12 @@ import org.apache.commons.lang.builder.ToStringStyle; import org.apache.maven.plugin.MojoExecutionException; import org.nuiton.i18n.I18n; -import org.nuiton.io.FileUpdaterHelper; import org.nuiton.io.MirroredFileUpdater; import org.nuiton.plugin.PluginHelper; import java.beans.Introspector; import java.io.File; -import java.lang.String; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Generates some java code from jaxx files. @@ -57,49 +48,54 @@ */ public class GenerateMojo extends AbstractJaxxMojo implements CompilerConfiguration { + /** Default includes to use, if none provided */ + private static final String[] INCLUDES = {"**\\/*.jaxx", "**\\/*.css"}; + /** - * Default includes to use, if none provided - */ - private static final String[] INCLUDES = {"**\\/*.jaxx"}; - /** * Repertoire sources des fichiers jaxx a generer. * * @parameter expression="${jaxx.src}" default-value="${basedir}/src/main/java" */ protected File src; + /** * Repertoire de destination des fichiers java a generer. * * @parameter expression="${jaxx.outJava}" default-value="${basedir}/target/generated-sources/java" */ protected File outJava; + /** * pour filter les fichiers a traiter * * @parameter expression="${jaxx.includes}" */ protected String[] includes; + /** * pour filter les fichiers a ne pas traiter * * @parameter expression="${jaxx.excludes}" */ protected String[] excludes; + /** * Le compilateur à utiliser (par défaut celui de Swing) * * @parameter expression="${jaxx.compilerFQN}" default-value="jaxx.compiler.JAXXCompiler" */ protected String compilerFQN; + /** * Le compilateur à utiliser (par défaut celui de Swing) * * @parameter expression="${jaxx.validatorFQN}" default-value="jaxx.runtime.validator.swing.SwingValidator" */ protected String validatorFQN; + /** - * the name of implementation of {@link JAXXContext}to be used on - * {@link JAXXObject}. + * the name of implementation of {@link JAXXContext}to be used on {@link + * JAXXObject}. * <p/> * Must not be abstract. * @@ -107,6 +103,7 @@ * @required */ protected String jaxxContextFQN; + /** * the FQN of the ui to use for error notification. * <p/> @@ -115,75 +112,88 @@ * @parameter expression="${jaxx.defaultErrorUIFQN}" */ protected String defaultErrorUIFQN; + /** * the FQN of the ui to use for error notification. * <p/> * If not given, will use the one defined in validator * - * @parameter expression="${jaxx.defaultDecoratorFQN}" default-value="jaxx.compiler.decorators.DefaultCompiledObjectDecorator" + * @parameter expression="${jaxx.defaultDecoratorFQN}" + * default-value="jaxx.compiler.decorators.DefaultCompiledObjectDecorator" * @see CompiledObjectDecorator */ protected String defaultDecoratorFQN; + /** - * flag to include in compiler classpath the java sources directories - * (src and outJava). + * flag to include in compiler classpath the java sources directories (src + * and outJava). * <p/> * By default, false. * - * @parameter expression="${jaxx.addSourcesToClassPath}" default-value="false" + * @parameter expression="${jaxx.addSourcesToClassPath}" + * default-value="false" */ protected boolean addSourcesToClassPath; + /** - * flag to include in compiler classpath the java resources directories - * (src and outJava). + * flag to include in compiler classpath the java resources directories (src + * and outJava). * <p/> * By default, false. * - * @parameter expression="${jaxx.addResourcesToClassPath}" default-value="false" + * @parameter expression="${jaxx.addResourcesToClassPath}" + * default-value="false" * @since 1.6.0 */ protected boolean addResourcesToClassPath; + /** - * flag to include in compiler classpath the compile class-path - * (can only be used in a test phase). + * flag to include in compiler classpath the compile class-path (can only be + * used in a test phase). * <p/> * By default, false. * - * @parameter expression="${jaxx.addCompileClassPath}" default-value="false" + * @parameter expression="${jaxx.addCompileClassPath}" + * default-value="false" * @since 1.6.0 */ protected boolean addCompileClassPath; + /** * flag to include in compiler classpath the project compile classpath. * <p/> * By default, false. * - * @parameter expression="${jaxx.addProjectClassPath}" default-value="false" + * @parameter expression="${jaxx.addProjectClassPath}" + * default-value="false" */ protected boolean addProjectClassPath; + /** - * A flag to mark themojo to be used in a test phase. This will permits - * to add generated sources in test compile roots. + * 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" * @since 1.6.0 */ protected boolean testPhase; + /** - * to make compiler i18nable, says add the - * {@link I18n#_(String, Object...)} method invocation on - * {@link I18nHelper#I18N_ATTRIBUTES} attributes. + * to make compiler i18nable, says add the {@link I18n#_(String, Object...)} + * method invocation on {@link I18nHelper#I18N_ATTRIBUTES} attributes. * * @parameter expression="${jaxx.i18nable}" default-value="true" * @see I18nHelper */ protected boolean i18nable; + /** * pour optimizer le code compile ou genere ? * * @parameter expression="${jaxx.optimize}" default-value="false" */ protected boolean optimize; + /** * flag to add logger to each generated jaxx file. * <p/> @@ -192,6 +202,7 @@ * @parameter expression="${jaxx.addLogger}" default-value="true" */ protected boolean addLogger; + /** * flag to keep compilers after the generate operation (usefull for tests. * <p/> @@ -200,11 +211,11 @@ * @parameter expression="${jaxx.resetAfterCompile}" default-value="true" */ protected boolean resetAfterCompile; + /** * extra path to be added in {@link Introspector#setBeanInfoSearchPath(String[])}. * <p/> - * add beanInfoSearchPath to be registred by - * {@link BeanInfoUtil#addJaxxBeanInfoPath(String...)} + * add beanInfoSearchPath to be registred by {@link BeanInfoUtil#addJaxxBeanInfoPath(String...)} * <p/> * and then will be use by {@link DefaultInitializer#initialize()}. * <p/> @@ -214,18 +225,22 @@ * @parameter expression="${jaxx.beanInfoSearchPath}" */ protected String[] beanInfoSearchPath; + /** * list of fqn of class toimport for all generated jaxx files * * @parameter expression="${jaxx.extraImportList}" */ protected String extraImportList; + /** * a flag to use UIManager to retreave icons. * - * @parameter expression="${jaxx.useUIManagerForIcon}" default-value="false" + * @parameter expression="${jaxx.useUIManagerForIcon}" + * default-value="false" */ protected boolean useUIManagerForIcon; + /** * flag to activate profile mode. * <p/> @@ -234,6 +249,7 @@ * @parameter expression="${jaxx.profile}" default-value="false" */ protected boolean profile; + /** * To show detected bindings. * <p/> @@ -243,6 +259,7 @@ * @since 2.0.0 */ protected boolean showBinding; + /** * the FQN of help broker * <p/> @@ -252,64 +269,75 @@ * @since 1.3 */ protected String helpBrokerFQN; - /** - * detected jaxx files in {@link #init()} method - */ + + /** detected jaxx files in {@link #init()} method */ protected String[] files; + /** * file updater used to detect jaxx files. * <p/> * <b>Note:</b> if {@link #verbose} flag is on, will ne be used */ protected MirroredFileUpdater updater; + /** * */ private Class<?> defaultErrorUIClass; + /** * */ private Class<?> validatorClass; + /** - * + * type of {@link CompiledObjectDecorator} to use */ private Class<? extends CompiledObjectDecorator> defaultDecoratorClass; + /** - * + * type of {@link JAXXContext} to use */ private Class<? extends JAXXContext> jaxxContextClass; + /** - * + * type of compiler to use */ private Class<? extends JAXXCompiler> compilerClass; + /** * */ private String[] extraImports; + /** - * + * internal state to known if a files has to be generated */ private boolean nofiles; + /** * */ protected ClassLoader cl; - /** - * JAXX engine - */ + + /** JAXX engine */ private JAXXEngine engine; @SuppressWarnings("unchecked") @Override public void init() throws Exception { + if (getLog().isDebugEnabled()) { + // if debug is on, then verbose also + setVerbose(true); + } fixCompileSourceRoots(); if (includes == null || includes.length == 0) { // use default includes includes = INCLUDES; } - updater = FileUpdaterHelper.newJaxxFileUpdater(src, outJava); + updater = new JaxxFileUpdater(src, outJava); Map<File, String[]> result = new HashMap<File, String[]>(); getFilesToTreateForRoots( @@ -321,18 +349,48 @@ files = result.get(src); + // Evolution #435: Regenerates jaxx files when his css file is modified + // filter css and jaxx files to obtain only jaxx files + // if a css is modified, try to find the corresponding jaxx files + if (files != null && files.length > 0) { + Set<String> filterFiles = new HashSet<String>(files.length); + for (String path : files) { + if (path.endsWith(".css")) { + // take the jaxx file + String jaxxFilePath = + path.substring(0, path.length() - 4) + ".jaxx"; + File f = new File(src, jaxxFilePath); + if (f.exists()) { + if (isVerbose()) { + getLog().info("will treate jaxx file from css " + + f); + } + filterFiles.add(jaxxFilePath); + } else { + getLog().warn("can not find jaxx file corresponding " + + "to modified css file " + path); + } + continue; + } + if (path.endsWith(".jaxx")) { + filterFiles.add(path); + } + } + files = filterFiles.toArray(new String[filterFiles.size()]); + } + nofiles = files == null || files.length == 0; if (nofiles) { return; } cl = initClassLoader(getProject(), - src, - addSourcesToClassPath, - testPhase, - addResourcesToClassPath, - addCompileClassPath, - addProjectClassPath); + src, + addSourcesToClassPath, + testPhase, + addResourcesToClassPath, + addCompileClassPath, + addProjectClassPath); Thread.currentThread().setContextClassLoader(cl); @@ -540,7 +598,7 @@ // no project defined, can not fix anything // this case could appear if we wanted to do some tests of the plugin return; - } + } if (testPhase) { addTestCompileSourceRoots(getTargetDirectory()); Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerTest.java =================================================================== --- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerTest.java 2010-03-31 13:20:30 UTC (rev 1825) +++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/CompilerTest.java 2010-03-31 18:57:47 UTC (rev 1826) @@ -24,11 +24,12 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.SystemStreamLog; -import static org.junit.Assert.*; import org.junit.Test; import java.io.File; +import static org.junit.Assert.*; + public class CompilerTest extends JaxxBaseTest { @Test Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java =================================================================== --- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java 2010-03-31 13:20:30 UTC (rev 1825) +++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/JaxxBaseTest.java 2010-03-31 18:57:47 UTC (rev 1826) @@ -20,7 +20,9 @@ */ package org.nuiton.jaxx.plugin; +import jaxx.compiler.decorators.DefaultCompiledObjectDecorator; import jaxx.runtime.context.DefaultJAXXContext; +import jaxx.runtime.validator.swing.SwingValidator; import org.nuiton.util.FileUtil; import java.io.File; @@ -53,11 +55,18 @@ @Override protected void setUpMojo(GenerateMojo mojo, File pomFile) throws Exception { - super.setUpMojo(mojo, pomFile); + try { + super.setUpMojo(mojo, pomFile); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error(e); + } + } mojo.jaxxContextFQN = DefaultJAXXContext.class.getName(); - mojo.compilerFQN = jaxx.compiler.JAXXCompiler.class.getName(); - mojo.validatorFQN = jaxx.runtime.validator.swing.SwingValidator.class.getName(); - mojo.defaultDecoratorFQN = jaxx.compiler.decorators.DefaultCompiledObjectDecorator.class.getName(); + mojo.compilerFQN = JAXXCompiler.class.getName(); + mojo.validatorFQN = SwingValidator.class.getName(); + mojo.defaultDecoratorFQN = DefaultCompiledObjectDecorator.class.getName(); + } protected void checkPattern(GenerateMojo mojo, String pattern, boolean required, String... files) throws IOException { Modified: trunk/maven-jaxx-plugin/src/test/resources/log4j.properties =================================================================== --- trunk/maven-jaxx-plugin/src/test/resources/log4j.properties 2010-03-31 13:20:30 UTC (rev 1825) +++ trunk/maven-jaxx-plugin/src/test/resources/log4j.properties 2010-03-31 18:57:47 UTC (rev 1826) @@ -5,5 +5,7 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n +log4j.logger.org.nuiton.plugin.AbstractMojoTest=INFO +log4j.logger.org.nuiton.jaxx=INFO log4j.logger.jaxx.compiler=INFO -log4j.logger.jaxx.compiler.binding=DEBUG +#log4j.logger.jaxx.compiler.binding=DEBUG
participants (1)
-
tchemit@users.nuiton.org