Index: maven-jrst-plugin/src/java/org/codelutin/jrst/plugin/JRstPlugin.java
diff -u maven-jrst-plugin/src/java/org/codelutin/jrst/plugin/JRstPlugin.java:1.8 maven-jrst-plugin/src/java/org/codelutin/jrst/plugin/JRstPlugin.java:1.9
--- maven-jrst-plugin/src/java/org/codelutin/jrst/plugin/JRstPlugin.java:1.8 Mon Mar 3 15:33:16 2008
+++ maven-jrst-plugin/src/java/org/codelutin/jrst/plugin/JRstPlugin.java Thu Jul 31 14:35:17 2008
@@ -23,18 +23,20 @@
* Created: 14 avril 2006
*
* @author ruchaud
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*
- * Last update: $Date: 2008-03-03 15:33:16 $
- * by : $Author: glandais $
+ * Last update: $Date: 2008-07-31 14:35:17 $
+ * by : $Author: bpoussin $
*/
package org.codelutin.jrst.plugin;
import java.io.File;
+import java.io.IOException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.NoBannerLogger;
import org.apache.tools.ant.Project;
@@ -45,7 +47,22 @@
import org.codelutin.util.FileUtil.FileAction;
/**
- * Génére du xdoc à partir de fichiers Rst
+ * Génére du xdoc à partir de fichiers Rst
+ *
+ * Les fichiers rst sont dans les repertoires:
+ *
src/site/fr/rst/
+ * src/site/en/rst/
+ * src/site/es/rst/
+ * ...
+ *
+ * et ils iront au final dans:
+ * target/site-build/fr/xdoc/
+ * target/site-build/en/xdoc/
+ * target/site-build/es/xdoc/
+ * ...
+ *
+ * tous les autres fichiers iront dans target/site-build en respectant la
+ * meme hierarchie de repertoire.
*
* @goal jrst
* @phase pre-site
@@ -54,10 +71,10 @@
/**
* Répertoire source des fichiers Rst
*
- * @parameter default-value="doc"
+ * @parameter default-value="src/site"
* @required
*/
- private String directoryIn = "doc";
+ private String directoryIn = "src/site";
/**
* Encoding en entrée
@@ -76,10 +93,10 @@
/**
* Répertoire cible des fichiers xdoc générée
*
- * @parameter default-value="target/site-build/xdoc"
+ * @parameter default-value="target/site-build"
* @required
*/
- private String directoryOut = "target/site-build/xdoc";
+ private String directoryOut = "target/site-build";
/**
* Arr�te la g�n�ration en cas d'erreurs
@@ -91,9 +108,15 @@
/**
* Ecrase les fichiers g�n�r�s
*
- * @parameter default-value="false"
+ * @parameter default-value="ifnewer"
+ */
+ private String overwrite = "ifnewer";
+
+ /**
+ *
+ * @parameter default-value="fr"
*/
- private boolean overwrite = false;
+ private String defaultLocale = "fr";
/**
* Permet d'obtenir plus d'information
@@ -102,9 +125,38 @@
*/
private boolean verbose = false;
+ /**
+ * Projet en cours de deploiement.
+ * @parameter expression="${project}"
+ */
+
+ private MavenProject project;
private int numberFilesGenerates;
+ /**
+ * Retourne la langue par defaut precisé dans le pom.xml
+ * @return
+ */
+ protected String getDefaultLocale() {
+ String result = defaultLocale;
+ return result;
+ }
+
+ /**
+ * @return the overwrite
+ */
+ public JRST.Overwrite getOverwrite() {
+ JRST.Overwrite result = JRST.Overwrite.NEVER;
+ if (this.overwrite.contains("new")) {
+ result = JRST.Overwrite.IFNEWER;
+ } else if ("true".equalsIgnoreCase(this.overwrite) ||
+ "alltime".equalsIgnoreCase(this.overwrite)) {
+ result = JRST.Overwrite.ALLTIME;
+ }
+ return result;
+ }
+
public void execute() throws MojoExecutionException {
try {
actionGenerate();
@@ -118,7 +170,7 @@
}
private void actionGenerate(){
- getLog().info("G�n�ration des fichier xdocs � partir des fichiers rst");
+ getLog().info("Génération des fichier xdocs à partir des fichiers rst");
numberFilesGenerates = 0;
FileUtil.walkAfter(new File(directoryIn), this);
getLog().info("Generating " + numberFilesGenerates + " files to " + directoryOut);
@@ -127,16 +179,26 @@
public boolean doAction(File file) {
String fileIn = file.getAbsoluteFile().toString();
String fileOut = null;
-
- if (fileIn.matches(".*\\.rst")) {
- fileOut = fileIn.replace(directoryIn,directoryOut).replace(".rst",".xml");
+ getLog().info("Using " + fileIn);
+ if (fileIn.matches(".*[/\\\\]rst[/\\\\].*\\.rst")) {
+ fileOut =
+ fileIn.replace(directoryIn, directoryOut)
+ .replace(".rst",".xml")
+ .replaceFirst("([/\\\\])rst([/\\\\])", "$1xdoc$2");
+
+ if (defaultLocale != null && !"".equals(defaultLocale)) {
+ fileOut = fileOut.replaceFirst("([/\\\\])" + defaultLocale + "([/\\\\])", "$1");
+ }
+
try {
JRST.generate(JRST.TYPE_XDOC,
- new File(fileIn), inputEncoding, new File(fileOut), outputEncoding, (overwrite ? JRST.Overwrite.ALLTIME : JRST.Overwrite.NEVER));
+ new File(fileIn), inputEncoding, new File(fileOut), outputEncoding, getOverwrite());
numberFilesGenerates ++;
} catch (Exception e) {
getLog().error(e);
- throw new GenerationJRstException(fileIn);
+ if(!ignoreErrors) {
+ throw new GenerationJRstException(fileIn);
+ }
}
}
@@ -151,35 +213,83 @@
getLog().info("Copie des fichiers images");
/* Execution de la tâche ant copy */
- /* Création d'un projet ant */
- Project project = new Project();
+ try {
+ if (defaultLocale != null && !"".equals(defaultLocale)) {
+ // copie de tous les fichiers non rst
+ FileUtil.copyAndRenameRecursively(
+ new File(directoryIn),
+ new File(directoryOut),
+ false,
+ "([/\\\\])" + defaultLocale + "([/\\\\])", "$1",
+ true,
+ ".*[/\\\\]rst[/\\\\].*");
+
+ // copie des images du repertoire rst dans le build-site
+ FileUtil.copyAndRenameRecursively(
+ new File(directoryIn),
+ new File(directoryOut),
+ false, // on ne copie que le contenu de directoryIn
+ "([/\\\\])" + defaultLocale + "([/\\\\])rst([/\\\\])",
+ "$1resources$2",
+ false,
+ ".*[/\\\\]rst[/\\\\].*(\\.png|\\.jpeg|\\.jpg|\\.gif)$");
+ } else {
+ // copie de tous les fichiers non rst
+ FileUtil.copyAndRenameRecursively(
+ new File(directoryIn),
+ new File(directoryOut),
+ false,
+ "",
+ "",
+ true,
+ ".*[/\\\\]rst[/\\\\].*");
+
+ // copie des images du repertoire rst dans le build-site
+ FileUtil.copyAndRenameRecursively(
+ new File(directoryIn),
+ new File(directoryOut),
+ false,
+ "([/\\\\])rst([/\\\\])",
+ "$1resources$2",
+ false,
+ ".*[/\\\\]rst[/\\\\].*(\\.png|\\.jpeg|\\.jpg|\\.gif)$");
+ }
+ } catch (IOException eee) {
+ getLog().error(eee);
+ }
- BuildLogger logger = new NoBannerLogger();
- logger.setMessageOutputLevel(org.apache.tools.ant.Project.MSG_INFO);
- logger.setOutputPrintStream(System.out);
- logger.setErrorPrintStream(System.err);
-
- project.init();
- project.getBaseDir();
- project.addBuildListener(logger);
-
- /* Création de la tâche ant Copy */
- Copy copy = new Copy();
- copy.setProject(project);
- copy.setTaskName("Copy images");
-
- /* Configuration */
- copy.setTodir(new File(directoryOut + "/resources")); // with maven2 site plugin images must be in resources
- copy.setPreserveLastModified(true);
- copy.setOverwrite(overwrite);
- FileSet fileSet = new FileSet();
- fileSet.setDir(new File(directoryIn));
- fileSet.setIncludes("**/*.png,**/*.jpeg,**/*.jpg,**/*.gif");
- copy.addFileset(fileSet);
+
- /* Execution */
- copy.execute();
+// /* Création d'un projet ant */
+// Project project = new Project();
+//
+// BuildLogger logger = new NoBannerLogger();
+// logger.setMessageOutputLevel(org.apache.tools.ant.Project.MSG_INFO);
+// logger.setOutputPrintStream(System.out);
+// logger.setErrorPrintStream(System.err);
+//
+// project.init();
+// project.getBaseDir();
+// project.addBuildListener(logger);
+//
+// /* Création de la tâche ant Copy */
+// Copy copy = new Copy();
+// copy.setProject(project);
+// copy.setTaskName("Copy images");
+//
+// /* Configuration */
+// copy.setTodir(new File(directoryOut + "/resources")); // with maven2 site plugin images must be in resources
+// copy.setPreserveLastModified(true);
+// copy.setOverwrite("true".equalsIgnoreCase(overwrite));
+//
+// FileSet fileSet = new FileSet();
+// fileSet.setDir(new File(directoryIn));
+// fileSet.setIncludes("**/*.png,**/*.jpeg,**/*.jpg,**/*.gif");
+// copy.addFileset(fileSet);
+//
+// /* Execution */
+// copy.execute();
}
}