Author: tchemit
Date: 2008-07-22 22:17:54 +0000 (Tue, 22 Jul 2008)
New Revision: 764
Added:
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
Removed:
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorGoal.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorGoal.java
Modified:
trunk/lutinjaxx/maven/src/test/java/org/codelutin/jaxx/CompilerTest.java
Log:
refactor goals
Deleted: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java 2008-07-22 22:17:15 UTC (rev 763)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java 2008-07-22 22:17:54 UTC (rev 764)
@@ -1,267 +0,0 @@
-/* *##%
- * Copyright (C) 2007
- * JaxxPlugin, Code Lutin
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *##%*/
-
-package org.codelutin.jaxx;
-
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codelutin.jaxx.action.ActionConfig;
-import org.codelutin.jaxx.action.SelectActionConfig;
-import org.codelutin.jaxx.action.ToggleActionConfig;
-import org.codelutin.util.FileUtil;
-import org.codelutin.util.SortedProperties;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Properties;
-
-/**
- * Classe permettant de generer le fichier de propri�t�s des actions d�tect�es.
- *
- * @author chemit
- * @goal generate-actions-properties
- * @phase process-classes
- */
-public class ActionGeneratorGoal extends AbstractActionGeneratorMojo {
-
- /**
- * @description R�pertoire sources des fichiers java � traiter.
- * @parameter expression="${jaxx.src}" default-value="${basedir}/src/main/java"
- */
- protected File src;
-
- /**
- * @description pour filter
- * @parameter expression="${jaxx.includes}"
- */
- protected String[] includes;
-
- /**
- * @description pour filter
- * @parameter expression="${jaxx.excludes}"
- */
- protected String[] excludes;
-
- protected String[] files;
-
- protected URLClassLoader loader;
-
- private static final String[] INCLUDES = {"**\\/*.java"};
-
-
- protected void doExecute() throws Exception {
-
- if (verbose) {
- printInit();
- }
-
- Properties result = loadProperties();
-
-
- saveProperties(result);
-
- }
-
- protected Properties loadProperties() throws ClassNotFoundException {
- Properties result = new SortedProperties();
- for (String file : files) {
- String fqn = file.substring(0, file.length() - 5).replaceAll("\\/", ".");
-
- if (getLog().isDebugEnabled()) {
- getLog().debug("fqn to treate " + fqn);
- }
-
- Class<?> clazz = Class.forName(fqn, false, loader);
-
- // try a ActionConfig
- ActionConfig actionConfig = clazz.getAnnotation(ActionConfig.class);
- if (actionConfig != null) {
-
- if (actionConfig.multiNames().length > 0) {
- // multinames
- registerEntry(clazz, result, actionConfig.multiNames());
- continue;
- }
-
- if (!actionConfig.actionCommand().isEmpty()) {
- registerEntry(clazz, result, actionConfig.actionCommand());
- continue;
- }
-
- getLog().warn("could not treate class " + clazz);
- continue;
- }
-
- // try a SelectActionConfig
- SelectActionConfig selectActionConfig = clazz.getAnnotation(SelectActionConfig.class);
- if (selectActionConfig != null) {
- if (selectActionConfig.multiNames().length > 0) {
- // multinames
- registerEntry(clazz, result, selectActionConfig.multiNames());
- continue;
- }
-
- if (!selectActionConfig.actionCommand().isEmpty()) {
- registerEntry(clazz, result, selectActionConfig.actionCommand());
- continue;
- }
- getLog().warn("could not treate class " + clazz);
- continue;
- }
-
- // try a toggleAction
- ToggleActionConfig toggleActionConfig = clazz.getAnnotation(ToggleActionConfig.class);
- if (toggleActionConfig != null) {
- if (toggleActionConfig.multiNames().length > 0) {
- // multinames
- registerEntry(clazz, result, toggleActionConfig.multiNames());
- continue;
- }
-
- if (!toggleActionConfig.actionCommand().isEmpty()) {
- registerEntry(clazz, result, toggleActionConfig.actionCommand());
- continue;
- }
-
- getLog().warn("could not treate class " + clazz);
- }
-
- }
- return result;
- }
-
- protected void saveProperties(Properties result) throws IOException {
- OutputStream writer = null;
- File generatedFile = new File(outResource, actionsFile);
- File parent = generatedFile.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
- try {
- writer = new org.codelutin.util.PropertiesDateRemoveFilterStream(new java.io.FileOutputStream(generatedFile));
-
- result.store(writer, null);
-
-
- } finally {
- if (writer != null) {
- writer.flush();
- writer.close();
- }
- }
-
- if (copyToCP) {
- // save it also in classes
- File compiledFile = new File(outClass, actionsFile);
- if (getLog().isDebugEnabled()) {
- getLog().debug("copy to classapth generated file " + compiledFile);
- }
- parent = compiledFile.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
- FileUtil.copy(generatedFile, compiledFile);
- }
- }
-
-
- @Override
- protected void init() {
-
- super.init();
-
- DirectoryScanner ds;
- ds = new DirectoryScanner();
- ds.setBasedir(src);
- boolean noIncludes = includes == null || includes.length == 0;
- ds.setIncludes(noIncludes ? INCLUDES : includes);
- boolean noExcludes = excludes == null || excludes.length == 0;
- if (!noExcludes) {
- ds.setExcludes(excludes);
- }
- ds.scan();
- files = ds.getIncludedFiles();
-
- getLog().info("jaxx-actions - found " + files.length + " file(s) to treate. ");
-
- loader = initClassLoader(project, getLog());
- }
-
- protected void registerEntry(Class<?> clazz, Properties result, String... names) {
- for (String name : names) {
- if (getLog().isDebugEnabled()) {
- getLog().debug("name: " + name + ", class:" + clazz);
- }
- result.put("action." + name, clazz.getName());
- }
- }
-
- protected void printInit() {
-
- for (String file : files) {
- getLog().debug(file);
- }
-
- printCP();
- }
-
- protected void printCP() {
-
- getLog().debug(loader.toString());
-
- for (URL url : loader.getURLs()) {
- getLog().debug("url in class loader " + url);
- }
- }
-
- public File getSrc() {
- return src;
- }
-
- public void setSrc(File src) {
- this.src = src;
- }
-
- public String[] getIncludes() {
- return includes;
- }
-
- public void setIncludes(String[] includes) {
- this.includes = includes;
- }
-
- public String[] getExcludes() {
- return excludes;
- }
-
- public void setExcludes(String[] excludes) {
- this.excludes = excludes;
- }
-
- public String[] getFiles() {
- return files;
- }
-
- public void setFiles(String[] files) {
- this.files = files;
- }
-
-}
\ No newline at end of file
Copied: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java (from rev 763, trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorGoal.java)
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java (rev 0)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java 2008-07-22 22:17:54 UTC (rev 764)
@@ -0,0 +1,267 @@
+/* *##%
+ * Copyright (C) 2007
+ * JaxxPlugin, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package org.codelutin.jaxx;
+
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codelutin.jaxx.action.ActionConfig;
+import org.codelutin.jaxx.action.SelectActionConfig;
+import org.codelutin.jaxx.action.ToggleActionConfig;
+import org.codelutin.util.FileUtil;
+import org.codelutin.util.SortedProperties;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Properties;
+
+/**
+ * Classe permettant de generer le fichier de propri�t�s des actions d�tect�es.
+ *
+ * @author chemit
+ * @goal generate-actions-properties
+ * @phase process-classes
+ */
+public class ActionGeneratorMojo extends AbstractActionGeneratorMojo {
+
+ /**
+ * @description R�pertoire sources des fichiers java � traiter.
+ * @parameter expression="${jaxx.src}" default-value="${basedir}/src/main/java"
+ */
+ protected File src;
+
+ /**
+ * @description pour filter
+ * @parameter expression="${jaxx.includes}"
+ */
+ protected String[] includes;
+
+ /**
+ * @description pour filter
+ * @parameter expression="${jaxx.excludes}"
+ */
+ protected String[] excludes;
+
+ protected String[] files;
+
+ protected URLClassLoader loader;
+
+ private static final String[] INCLUDES = {"**\\/*.java"};
+
+
+ protected void doExecute() throws Exception {
+
+ if (verbose) {
+ printInit();
+ }
+
+ Properties result = loadProperties();
+
+
+ saveProperties(result);
+
+ }
+
+ protected Properties loadProperties() throws ClassNotFoundException {
+ Properties result = new SortedProperties();
+ for (String file : files) {
+ String fqn = file.substring(0, file.length() - 5).replaceAll("\\/", ".");
+
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("fqn to treate " + fqn);
+ }
+
+ Class<?> clazz = Class.forName(fqn, false, loader);
+
+ // try a ActionConfig
+ ActionConfig actionConfig = clazz.getAnnotation(ActionConfig.class);
+ if (actionConfig != null) {
+
+ if (actionConfig.multiNames().length > 0) {
+ // multinames
+ registerEntry(clazz, result, actionConfig.multiNames());
+ continue;
+ }
+
+ if (!actionConfig.actionCommand().isEmpty()) {
+ registerEntry(clazz, result, actionConfig.actionCommand());
+ continue;
+ }
+
+ getLog().warn("could not treate class " + clazz);
+ continue;
+ }
+
+ // try a SelectActionConfig
+ SelectActionConfig selectActionConfig = clazz.getAnnotation(SelectActionConfig.class);
+ if (selectActionConfig != null) {
+ if (selectActionConfig.multiNames().length > 0) {
+ // multinames
+ registerEntry(clazz, result, selectActionConfig.multiNames());
+ continue;
+ }
+
+ if (!selectActionConfig.actionCommand().isEmpty()) {
+ registerEntry(clazz, result, selectActionConfig.actionCommand());
+ continue;
+ }
+ getLog().warn("could not treate class " + clazz);
+ continue;
+ }
+
+ // try a toggleAction
+ ToggleActionConfig toggleActionConfig = clazz.getAnnotation(ToggleActionConfig.class);
+ if (toggleActionConfig != null) {
+ if (toggleActionConfig.multiNames().length > 0) {
+ // multinames
+ registerEntry(clazz, result, toggleActionConfig.multiNames());
+ continue;
+ }
+
+ if (!toggleActionConfig.actionCommand().isEmpty()) {
+ registerEntry(clazz, result, toggleActionConfig.actionCommand());
+ continue;
+ }
+
+ getLog().warn("could not treate class " + clazz);
+ }
+
+ }
+ return result;
+ }
+
+ protected void saveProperties(Properties result) throws IOException {
+ OutputStream writer = null;
+ File generatedFile = new File(outResource, actionsFile);
+ File parent = generatedFile.getParentFile();
+ if (!parent.exists()) {
+ parent.mkdirs();
+ }
+ try {
+ writer = new org.codelutin.util.PropertiesDateRemoveFilterStream(new java.io.FileOutputStream(generatedFile));
+
+ result.store(writer, null);
+
+
+ } finally {
+ if (writer != null) {
+ writer.flush();
+ writer.close();
+ }
+ }
+
+ if (copyToCP) {
+ // save it also in classes
+ File compiledFile = new File(outClass, actionsFile);
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("copy to classapth generated file " + compiledFile);
+ }
+ parent = compiledFile.getParentFile();
+ if (!parent.exists()) {
+ parent.mkdirs();
+ }
+ FileUtil.copy(generatedFile, compiledFile);
+ }
+ }
+
+
+ @Override
+ protected void init() {
+
+ super.init();
+
+ DirectoryScanner ds;
+ ds = new DirectoryScanner();
+ ds.setBasedir(src);
+ boolean noIncludes = includes == null || includes.length == 0;
+ ds.setIncludes(noIncludes ? INCLUDES : includes);
+ boolean noExcludes = excludes == null || excludes.length == 0;
+ if (!noExcludes) {
+ ds.setExcludes(excludes);
+ }
+ ds.scan();
+ files = ds.getIncludedFiles();
+
+ getLog().info("jaxx-actions - found " + files.length + " file(s) to treate. ");
+
+ loader = initClassLoader(project, getLog());
+ }
+
+ protected void registerEntry(Class<?> clazz, Properties result, String... names) {
+ for (String name : names) {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("name: " + name + ", class:" + clazz);
+ }
+ result.put("action." + name, clazz.getName());
+ }
+ }
+
+ protected void printInit() {
+
+ for (String file : files) {
+ getLog().debug(file);
+ }
+
+ printCP();
+ }
+
+ protected void printCP() {
+
+ getLog().debug(loader.toString());
+
+ for (URL url : loader.getURLs()) {
+ getLog().debug("url in class loader " + url);
+ }
+ }
+
+ public File getSrc() {
+ return src;
+ }
+
+ public void setSrc(File src) {
+ this.src = src;
+ }
+
+ public String[] getIncludes() {
+ return includes;
+ }
+
+ public void setIncludes(String[] includes) {
+ this.includes = includes;
+ }
+
+ public String[] getExcludes() {
+ return excludes;
+ }
+
+ public void setExcludes(String[] excludes) {
+ this.excludes = excludes;
+ }
+
+ public String[] getFiles() {
+ return files;
+ }
+
+ public void setFiles(String[] files) {
+ this.files = files;
+ }
+
+}
\ No newline at end of file
Deleted: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorGoal.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorGoal.java 2008-07-22 22:17:15 UTC (rev 763)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorGoal.java 2008-07-22 22:17:54 UTC (rev 764)
@@ -1,152 +0,0 @@
-/* *##%
- * Copyright (C) 2007
- * JaxxPlugin, Code Lutin
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *##%*/
-
-package org.codelutin.jaxx;
-
-import org.codelutin.jaxx.action.ActionProvider;
-import org.codelutin.util.FileUtil;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Classe permettant de generer un {@link org.codelutin.jaxx.action.ActionProvider} et son fichier de d�claration.
- *
- * @author chemit
- * @goal generate-actions-provider
- * @phase process-resources
- */
-public class ActionProviderGeneratorGoal extends AbstractActionGeneratorMojo {
-
- /**
- * @description FQN de la classe � g�n�rer.
- * @parameter expression="${jaxx.fqn}"
- * @required
- */
- protected String fqn;
-
- /**
- * @description nom logique du provider � g�n�rer.
- * @parameter expression="${jaxx.providerName}"
- * @required
- */
- protected String providerName;
-
- /**
- * @description FQN de la classe d'action � utiliser.
- * @parameter expression="${jaxx.fqnAction}"
- * @required
- */
- protected String fqnAction;
-
- /**
- * template of ActionProvider
- * $1 : package of class
- * $2 : simple name of class
- * $3 : abstract action fqn
- * $4 : path to actions properties file
- * $5 : provider name
- */
- protected static final String PROVIDER_TEMPLATE =
- "package %1$s;\n" +
- "\n" +
- "public class %2$s extends org.codelutin.jaxx.action.ActionProviderFromProperties<%3$s> {\n" +
- "\n" +
- " public %2$s() {\n" +
- " super(\"%5$s\", %3$s.class, \"%4$s\");\n" +
- " }\n" +
- "\n" +
- "}\n";
-
- protected File generateJavaProvider;
-
- protected File generatedProviderDeclaration;
-
-
- protected void doExecute() throws Exception {
-
- generateProvider();
-
- generateProviderDeclaration();
-
- }
-
- protected void generateProvider() throws IOException {
-
- int index = fqn.lastIndexOf(".");
- String packageJava = fqn.substring(0, index);
- String simpleJavaName = fqn.substring(index + 1);
-
- //TODO check if file was modified
- String content = String.format(PROVIDER_TEMPLATE,
- packageJava,
- simpleJavaName,
- fqnAction,
- actionsFile,
- providerName
- );
-
- FileUtil.writeString(generateJavaProvider, content);
- }
-
- protected void generateProviderDeclaration() throws IOException {
-
- //TODO check if file was modified
-
- // just add the fqn inside the file :)
- FileUtil.writeString(generatedProviderDeclaration, fqn);
-
- if (copyToCP) {
- // save it also in classes (since we are in process-resources phase and resources has already been copied)
- String path = generatedProviderDeclaration.getAbsolutePath().substring(outResource.getAbsolutePath().length() + 1);
- File compiledFile = new File(outClass, path);
- if (getLog().isDebugEnabled()) {
- getLog().debug("copy to classapth generated file " + compiledFile);
- }
- File parent = compiledFile.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
- FileUtil.copy(generatedProviderDeclaration, compiledFile);
- }
- }
-
- @Override
- protected void init() {
-
- super.init();
-
- generateJavaProvider = new File(outJava, fqn.replaceAll("\\.", java.io.File.separator) + ".java");
-
- File parent = generateJavaProvider.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
-
- generatedProviderDeclaration = new File(outResource, "META-INF/services/" + ActionProvider.class.getName());
- parent = generatedProviderDeclaration.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
-
- fixCompileSourceRoots();
-
- }
-
-}
\ No newline at end of file
Copied: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java (from rev 763, trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorGoal.java)
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java (rev 0)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-07-22 22:17:54 UTC (rev 764)
@@ -0,0 +1,152 @@
+/* *##%
+ * Copyright (C) 2007
+ * JaxxPlugin, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package org.codelutin.jaxx;
+
+import org.codelutin.jaxx.action.ActionProvider;
+import org.codelutin.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Classe permettant de generer un {@link org.codelutin.jaxx.action.ActionProvider} et son fichier de d�claration.
+ *
+ * @author chemit
+ * @goal generate-actions-provider
+ * @phase process-resources
+ */
+public class ActionProviderGeneratorMojo extends AbstractActionGeneratorMojo {
+
+ /**
+ * @description FQN de la classe � g�n�rer.
+ * @parameter expression="${jaxx.fqn}"
+ * @required
+ */
+ protected String fqn;
+
+ /**
+ * @description nom logique du provider � g�n�rer.
+ * @parameter expression="${jaxx.providerName}"
+ * @required
+ */
+ protected String providerName;
+
+ /**
+ * @description FQN de la classe d'action � utiliser.
+ * @parameter expression="${jaxx.fqnAction}"
+ * @required
+ */
+ protected String fqnAction;
+
+ /**
+ * template of ActionProvider
+ * $1 : package of class
+ * $2 : simple name of class
+ * $3 : abstract action fqn
+ * $4 : path to actions properties file
+ * $5 : provider name
+ */
+ protected static final String PROVIDER_TEMPLATE =
+ "package %1$s;\n" +
+ "\n" +
+ "public class %2$s extends org.codelutin.jaxx.action.ActionProviderFromProperties<%3$s> {\n" +
+ "\n" +
+ " public %2$s() {\n" +
+ " super(\"%5$s\", %3$s.class, \"%4$s\");\n" +
+ " }\n" +
+ "\n" +
+ "}\n";
+
+ protected File generateJavaProvider;
+
+ protected File generatedProviderDeclaration;
+
+
+ protected void doExecute() throws Exception {
+
+ generateProvider();
+
+ generateProviderDeclaration();
+
+ }
+
+ protected void generateProvider() throws IOException {
+
+ int index = fqn.lastIndexOf(".");
+ String packageJava = fqn.substring(0, index);
+ String simpleJavaName = fqn.substring(index + 1);
+
+ //TODO check if file was modified
+ String content = String.format(PROVIDER_TEMPLATE,
+ packageJava,
+ simpleJavaName,
+ fqnAction,
+ actionsFile,
+ providerName
+ );
+
+ FileUtil.writeString(generateJavaProvider, content);
+ }
+
+ protected void generateProviderDeclaration() throws IOException {
+
+ //TODO check if file was modified
+
+ // just add the fqn inside the file :)
+ FileUtil.writeString(generatedProviderDeclaration, fqn);
+
+ if (copyToCP) {
+ // save it also in classes (since we are in process-resources phase and resources has already been copied)
+ String path = generatedProviderDeclaration.getAbsolutePath().substring(outResource.getAbsolutePath().length() + 1);
+ File compiledFile = new File(outClass, path);
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("copy to classapth generated file " + compiledFile);
+ }
+ File parent = compiledFile.getParentFile();
+ if (!parent.exists()) {
+ parent.mkdirs();
+ }
+ FileUtil.copy(generatedProviderDeclaration, compiledFile);
+ }
+ }
+
+ @Override
+ protected void init() {
+
+ super.init();
+
+ generateJavaProvider = new File(outJava, fqn.replaceAll("\\.", java.io.File.separator) + ".java");
+
+ File parent = generateJavaProvider.getParentFile();
+ if (!parent.exists()) {
+ parent.mkdirs();
+ }
+
+ generatedProviderDeclaration = new File(outResource, "META-INF/services/" + ActionProvider.class.getName());
+ parent = generatedProviderDeclaration.getParentFile();
+ if (!parent.exists()) {
+ parent.mkdirs();
+ }
+
+ fixCompileSourceRoots();
+
+ }
+
+}
\ No newline at end of file
Deleted: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorGoal.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorGoal.java 2008-07-22 22:17:15 UTC (rev 763)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorGoal.java 2008-07-22 22:17:54 UTC (rev 764)
@@ -1,159 +0,0 @@
-/* *##%
- * Copyright (C) 2007
- * JaxxPlugin, Code Lutin
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *##%*/
-
-package org.codelutin.jaxx;
-
-import jaxx.compiler.CompilerOptions;
-import jaxx.compiler.JAXXCompiler;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.util.DirectoryScanner;
-
-import java.io.File;
-
-/**
- * Classe permettant de transformer des sources jaxx vers du source java.
- *
- * @author chemit
- * @goal generate
- * @phase process-resources
- */
-public class JaxxGeneratorGoal extends AbstractJaxxMojo {
-
- /**
- * @description R�pertoire sources des fichiers jaxx � g�n�rer.
- * @parameter expression="${jaxx.src}" default-value="${basedir}/src/uimodel"
- */
- protected File src;
-
- /**
- * @description pour optimizer le code compil� ou g�n�r� ?
- * @parameter expression="${jaxx.optimize}" default-value="false"
- */
- protected boolean optimize;
-
- /**
- * @description les options de la compilation
- * @parameter expression="${jaxx.javaOpts}"
- */
- protected String javaOpts = null;
-
- /**
- * @description pour filter
- * @parameter expression="${jaxx.includes}"
- */
- protected String[] includes;
-
- protected String[] files;
-
- private static final String[] INCLUDES = {"**\\/*.jaxx"};
-
- protected CompilerOptions options;
-
- protected void init() {
- super.init();
-
- fixCompileSourceRoots();
-
- DirectoryScanner ds;
- ds = new DirectoryScanner();
- ds.setBasedir(src);
- boolean noIncludes = includes == null || includes.length == 0;
- ds.setIncludes(noIncludes ? INCLUDES : includes);
- ds.scan();
- files = ds.getIncludedFiles();
- getLog().info("jaxx - found " + files.length + " file(s) to generate. ");
- options = toCompilerOptions();
-
- if (verbose) {
- printInit();
- }
-
- }
-
- protected void doExecute() throws Exception {
- if (!JAXXCompiler.compile(src, files, options)) {
- throw new MojoFailureException("Aborting due to errors reported by jaxxc");
- }
- }
-
- public CompilerOptions toCompilerOptions() {
- CompilerOptions result = new CompilerOptions();
- result.setClassPath(src.getPath());
- if (javaOpts != null && !"".equals(javaOpts)) {
- result.setJavacOpts(javaOpts);
- }
- result.setKeepJavaFiles(true);
- result.setOptimize(optimize);
- result.setJavacTargetDirectory(outClass);
- result.setTargetDirectory(outJava);
- return result;
- }
-
- protected void printInit() {
- getLog().debug("classPath: " + options.getClassPath());
- getLog().debug("javaOut : " + options.getTargetDirectory());
- getLog().debug("outClass : " + options.getJavacTargetDirectory());
- getLog().debug("javacOpts: " + options.getJavacOpts());
- getLog().debug("optiomize: " + options.getOptimize());
- for (String file : files) {
- getLog().debug(file);
- }
- }
-
- public File getSrc() {
- return src;
- }
-
- public void setSrc(File src) {
- this.src = src;
- }
-
- public boolean isOptimize() {
- return optimize;
- }
-
- public void setOptimize(boolean optimize) {
- this.optimize = optimize;
- }
-
- public String getJavaOpts() {
- return javaOpts;
- }
-
- public void setJavaOpts(String javaOpts) {
- this.javaOpts = javaOpts;
- }
-
- public String[] getIncludes() {
- return includes;
- }
-
- public void setIncludes(String[] includes) {
- this.includes = includes;
- }
-
- public String[] getFiles() {
- return files;
- }
-
- public void setFiles(String[] files) {
- this.files = files;
- }
-
-}
\ No newline at end of file
Copied: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java (from rev 762, trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorGoal.java)
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java (rev 0)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-07-22 22:17:54 UTC (rev 764)
@@ -0,0 +1,159 @@
+/* *##%
+ * Copyright (C) 2007
+ * JaxxPlugin, Code Lutin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package org.codelutin.jaxx;
+
+import jaxx.compiler.CompilerOptions;
+import jaxx.compiler.JAXXCompiler;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+import java.io.File;
+
+/**
+ * Classe permettant de transformer des sources jaxx vers du source java.
+ *
+ * @author chemit
+ * @goal generate
+ * @phase process-resources
+ */
+public class JaxxGeneratorMojo extends AbstractJaxxMojo {
+
+ /**
+ * @description R�pertoire sources des fichiers jaxx � g�n�rer.
+ * @parameter expression="${jaxx.src}" default-value="${basedir}/src/uimodel"
+ */
+ protected File src;
+
+ /**
+ * @description pour optimizer le code compil� ou g�n�r� ?
+ * @parameter expression="${jaxx.optimize}" default-value="false"
+ */
+ protected boolean optimize;
+
+ /**
+ * @description les options de la compilation
+ * @parameter expression="${jaxx.javaOpts}"
+ */
+ protected String javaOpts = null;
+
+ /**
+ * @description pour filter
+ * @parameter expression="${jaxx.includes}"
+ */
+ protected String[] includes;
+
+ protected String[] files;
+
+ private static final String[] INCLUDES = {"**\\/*.jaxx"};
+
+ protected CompilerOptions options;
+
+ protected void init() {
+ super.init();
+
+ fixCompileSourceRoots();
+
+ DirectoryScanner ds;
+ ds = new DirectoryScanner();
+ ds.setBasedir(src);
+ boolean noIncludes = includes == null || includes.length == 0;
+ ds.setIncludes(noIncludes ? INCLUDES : includes);
+ ds.scan();
+ files = ds.getIncludedFiles();
+ getLog().info("jaxx - found " + files.length + " file(s) to generate. ");
+ options = toCompilerOptions();
+
+ if (verbose) {
+ printInit();
+ }
+
+ }
+
+ protected void doExecute() throws Exception {
+ if (!JAXXCompiler.compile(src, files, options)) {
+ throw new MojoFailureException("Aborting due to errors reported by jaxxc");
+ }
+ }
+
+ public CompilerOptions toCompilerOptions() {
+ CompilerOptions result = new CompilerOptions();
+ result.setClassPath(src.getPath());
+ if (javaOpts != null && !"".equals(javaOpts)) {
+ result.setJavacOpts(javaOpts);
+ }
+ result.setKeepJavaFiles(true);
+ result.setOptimize(optimize);
+ result.setJavacTargetDirectory(outClass);
+ result.setTargetDirectory(outJava);
+ return result;
+ }
+
+ protected void printInit() {
+ getLog().debug("classPath: " + options.getClassPath());
+ getLog().debug("javaOut : " + options.getTargetDirectory());
+ getLog().debug("outClass : " + options.getJavacTargetDirectory());
+ getLog().debug("javacOpts: " + options.getJavacOpts());
+ getLog().debug("optiomize: " + options.getOptimize());
+ for (String file : files) {
+ getLog().debug(file);
+ }
+ }
+
+ public File getSrc() {
+ return src;
+ }
+
+ public void setSrc(File src) {
+ this.src = src;
+ }
+
+ public boolean isOptimize() {
+ return optimize;
+ }
+
+ public void setOptimize(boolean optimize) {
+ this.optimize = optimize;
+ }
+
+ public String getJavaOpts() {
+ return javaOpts;
+ }
+
+ public void setJavaOpts(String javaOpts) {
+ this.javaOpts = javaOpts;
+ }
+
+ public String[] getIncludes() {
+ return includes;
+ }
+
+ public void setIncludes(String[] includes) {
+ this.includes = includes;
+ }
+
+ public String[] getFiles() {
+ return files;
+ }
+
+ public void setFiles(String[] files) {
+ this.files = files;
+ }
+
+}
\ No newline at end of file
Modified: trunk/lutinjaxx/maven/src/test/java/org/codelutin/jaxx/CompilerTest.java
===================================================================
--- trunk/lutinjaxx/maven/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-07-22 22:17:15 UTC (rev 763)
+++ trunk/lutinjaxx/maven/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-07-22 22:17:54 UTC (rev 764)
@@ -10,7 +10,7 @@
public class CompilerTest extends TestCase {
- protected JaxxGeneratorGoal goal;
+ protected JaxxGeneratorMojo goal;
protected static final String PREFIX_PACKAGE = "testcases";
@@ -54,7 +54,7 @@
final File classOutDir = getClassOutDir();
assertTrue("could not found classOutDir (or not existing) : " + classOutDir + " on test " + getClass(), classOutDir != null && classOutDir.exists());
String packageName = anno.packageName();
- goal = new JaxxGeneratorGoal();
+ goal = new JaxxGeneratorMojo();
goal.setSrc(srcDir);
goal.setOutJava(outDir);
goal.setOutClass(classOutDir);